Forum » Programska oprema » access -> word ali excel
access -> word ali excel
![](https://static.slo-tech.com/stili/avatar_gray.gif)
marvin42 ::
Iz neke baze v Accessu printam zadeve... vse skupaj je poštimano res lepo, komplicirane tabele, text, itd... Včasih pa bi v to zadevo rad kaj na roke dodal (npr v tabelo vrinil kakšen text ali dodal kakšno opombo) in takrat se znajdem pred težavo. Izvoz v Word ali Excel je v Accessu skoraj neuporaben (je ok, dokler imaš opravka samo s textom, pri tabelah pa ne gre). Zdaj vse skupaj rešujem tako, da shranim kot pdf in potem s kakšnim ocr programom pretvorim v rtf. Zamudno, pa še zanesljivo ni. Ima kdo kakšno lažjo rešitev?
Mostly Harmless
![](https://static.slo-tech.com/stili/avatar_gray.gif)
marvin42 ::
stvar mora biti tako preprosta, da lahko vsak človek s par kliki zadevo vrže v word in tam popravlja... vedno gre za drugačne kozmetične popravke, kar je nemogoče vnaprej predvideti in pripraviti.
Mostly Harmless
![](https://static.slo-tech.com/stili/avatar_gray.gif)
zavajon ::
Potem naredi wordov template s formo, kjer bo uporabnik izbral, kaj in od kod bi prenašal podatke in makro za prenos nekako takole:
Sub CopyTable()
On Error GoTo CopyTable_E
Dim cnn As New ADODB.connection
Dim rst As New ADODB.Recordset
Dim tbl As Table
Dim flds As ADODB.Fields
Dim fld As ADODB.Field
Dim i&
With cnn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\test.mdb"
.Open
End With
With rst
.ActiveConnection = cnn
.Source = "select * from TEST"
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open
Set flds = .Fields
End With
Set tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=1, NumColumns:=flds.Count, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
With tbl
' glava
For Each fld In flds
i = i + 1
.Rows(1).Cells(i).Select
Selection.TypeText Text:=fld.Name
Next fld
' polni podatke
While Not rst.EOF
Selection.InsertRowsBelow 1
i = 0
For Each fld In flds
i = i + 1
.Rows(.Rows.Count).Cells(i).Select
Selection.TypeText Text:=fld.Value
Next fld
rst.MoveNext
Wend
.Rows(1).Select
Selection.Font.Bold = wdToggle
End With
CopyTable_X:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
CopyTable_E:
MsgBox Err.Description
Resume CopyTable_X
End Sub
Templatu moraš referencirati "Microsoft ActiveX Data Objects"
lp
Sub CopyTable()
On Error GoTo CopyTable_E
Dim cnn As New ADODB.connection
Dim rst As New ADODB.Recordset
Dim tbl As Table
Dim flds As ADODB.Fields
Dim fld As ADODB.Field
Dim i&
With cnn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\test.mdb"
.Open
End With
With rst
.ActiveConnection = cnn
.Source = "select * from TEST"
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open
Set flds = .Fields
End With
Set tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=1, NumColumns:=flds.Count, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
With tbl
' glava
For Each fld In flds
i = i + 1
.Rows(1).Cells(i).Select
Selection.TypeText Text:=fld.Name
Next fld
' polni podatke
While Not rst.EOF
Selection.InsertRowsBelow 1
i = 0
For Each fld In flds
i = i + 1
.Rows(.Rows.Count).Cells(i).Select
Selection.TypeText Text:=fld.Value
Next fld
rst.MoveNext
Wend
.Rows(1).Select
Selection.Font.Bold = wdToggle
End With
CopyTable_X:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
CopyTable_E:
MsgBox Err.Description
Resume CopyTable_X
End Sub
Templatu moraš referencirati "Microsoft ActiveX Data Objects"
lp
![](https://static.slo-tech.com/stili/avatar_gray.gif)
zavajon ::
Aja, pa če nočeš, da bo procedura vidna v seznamu makrojev (t.j. poganja se npr. iz forme, sicer pa je uporabnik ne more pognati), ji daj en dummy argument.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | vba arrayOddelek: Programiranje | 903 (596) | Vazelin |
» | [VB] datagridviewOddelek: Programiranje | 1905 (1288) | korenje3 |
» | VISUAL BASIC - Makro v wordu - prenos podatkov iz tabel v excelOddelek: Programiranje | 2855 (2717) | FlashM |
» | Kako do podatka v queryu iz VisualBasicScripta (VBA) v accessu?Oddelek: Programiranje | 2113 (1998) | Fim |
» | printanje v VB6.0Oddelek: Programiranje | 864 (768) | Zzzzzzz |