Está en la página 1de 5

lmporLar ho[a excell a access usando codlgo vb (24/08/04)

neceslLo crear una apllcaclon vb60 para lmporLar varlas ho[as excel 2000 a access2000 usando
codlgo vb
podrlas envlarme e[emplos con codlgo??
muchas graclas
me han hablado de crear macro en access y uLlllzarla desde vb pero no se como se llama a la
macro desde vbnl como se consLrulrla la macro





LxperLo


Ln un lC8MuLA8lC C8LA un 8C1Cn Command1 ? 8uL8A LS 1L L!LMLC CuL LxporLa el
conLenldo de una base de daLos Access 2000 medlanLe uAC 36 a Lxcel
C8LA unA 8u ACCLS CCn LL nCM88L db1 Labla1
nCM88L
ul8LCClCn
C8LAClCn
CAn1luAu
y agregale valores

CpLlon LxpllclL

rlvaLe Sub Command1_Cllck()
ulm P As Long PorlzonLal
ulm v As Long verLlcal
ulm Ml8ase As uaLabase
ulm Ml1abla As 8ecordseL

Cn Lrror Co1o LrrorLxcel

ulm ob[Lxcel As LxcelAppllcaLlon

SeL Ml8ase CpenuaLabase(Curulr() db1mdb)
SeL Ml1abla Ml8aseCpen8ecordseL(SLLLC1 * l8CM 1abla1 C8uL8 8? nombre ASC
dbCpenuynaseL)

lf Ml1abla8ecordCounL 0 1hen
Msg8ox La base de daLos esLa vacla
LxlL Sub
Lnd lf

SeL ob[Lxcel new LxcelAppllcaLlon
ob[Lxcelvlslble 1rue
deLermlna el numero de ho[as que se mosLrara en el Lxcel
ob[LxcelSheeLslnnewWorkbook 1
Crea el Llbro
ob[LxcelWorkbooksAdd

WlLh ob[LxcelAcLlveSheeL
8ange(Cells(1 1) Cells(1 4))8ordersLlneSLyle xlConLlnuous
Cells(3 1) nCM88L
Cells(3 2) ul8LCClCn
Cells(3 3) C8LAClCn
Cells(3 4) CAn1luAu
8ange(Cells(3 1) Cells(3 4))lonL8old 1rue

Columns(u)PorlzonLalAllgnmenL xlPAllgn8lghL
Columns(A)ColumnWldLh 30
Columns(8)ColumnWldLh 30
Columns(C)ColumnWldLh 30
Columns(u)ColumnWldLh 13
Lnd WlLh
ob[LxcelAcLlveSheeLCells(1 1) 8ASL uL uA1CS
ob[LxcelAcLlveSheeL8ange(ob[LxcelAcLlveSheeLCells(1 1) ob[LxcelAcLlveSheeLCells(1
4))PorlzonLalAllgnmenL xlPAllgnCenLerAcrossSelecLlon
WlLh ob[LxcelAcLlveSheeLCells(1 1)lonL
Color vb8ed
Slze 14
8old 1rue
Lnd WlLh

v 4
P 1
uo Whlle noL Ml1ablaLCl
uoLvenLs
ob[LxcelAcLlveSheeLCells(v P) Ml1ablallelds!nombre
ob[LxcelAcLlveSheeLCells(v P + 1) Ml1ablallelds!ulrecclon
ob[LxcelAcLlveSheeLCells(v P + 2) Ml1ablallelds!oblaclon
ob[LxcelAcLlveSheeLCells(v P + 3) Ml1ablallelds!CanLldad
v v + 1
Ml1ablaMovenexL
Loop

v v + 3
ob[Lxcel8ange(ob[LxcelCells(v 1) ob[LxcelCells(v 4))8ordersLlneSLyle xlConLlnuous
ob[LxcelAcLlveSheeL8ange(ob[LxcelAcLlveSheeLCells(v 1) ob[LxcelAcLlveSheeLCells(v
4))PorlzonLalAllgnmenL xlPAllgnCenLerAcrossSelecLlon
ob[LxcelAcLlveSheeLCells(v 1) uA1CS lMC81AuCS uL LxCLL

Ml8aseClose

SeL ob[Lxcel noLhlng
LxlL Sub

LrrorLxcel
Msg8ox Pa ocurrldo un error de conexln con Lxcel _
Chr(13) Chr(13) Lrror Lrrnumber _
Chr(13) lnfo LrruescrlpLlon _
Chr(13) Cb[eLo LrrSource _
Chr(13) Chr(13) Lnvle esLe error a la dlreccln prog1000[yahoocom _
y le lndlcaran la solucln a su problema vbCrlLlcal Lrror al conecLar con Lxcel
Lnd Sub

También podría gustarte