Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

automazione access-word - inserire tabella

107 views
Skip to first unread message

Akery

unread,
Jan 4, 2022, 5:31:10 AM1/4/22
to
Buongiorno,

è possibile per access inserire una tabella in word?
Attualmente attraverso i bookmaker riesco a inserire i valori di un
campo ma non ho trovato il modo di inserire una tabella di poche righe.

se non è possibile come si può accodare più righe?

Saluti

--
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
https://www.avast.com/antivirus

Karl Donaubauer

unread,
Jan 4, 2022, 6:18:48 AM1/4/22
to
Salve,

Akery:
> è possibile per access inserire una tabella in word?
> Attualmente attraverso i bookmaker riesco a inserire i valori di un
> campo ma non ho trovato il modo di inserire una tabella di poche righe.
> ...

Certo puoi inserire una tabella con il commando Tables.Add di Word VBA.
p.e. così

Set wdRng = wdDoc.Bookmarks("QuiVoglioPosizionareLaTabella").Range
Set wdTab = wdDoc.Tables.Add (wdRng, 12, 3) 'con 12 righe e 3 colonne

Dovresti trovare altri esempi sul web, o puoi farti aiutare dal
registratore di macro di Word.

Ciao
Karl
*********
Access News: https://youtu.be/wpPYu6G_xcY
Access DevCon: http://AccessDevCon.com
Access FAQ: https://www.donkarl.com/it

Akery

unread,
Jan 4, 2022, 9:05:47 AM1/4/22
to
dopo 1000 tentativi ha funzionato!!!


riporto il codice se può essere utile per qualcuno


Private Sub Comando32_Click()
Dim Wrd As Word.Application
Dim Doc As Word.Document
Dim GetDBPath As String
Dim dataf As Integer
Dim subfold As String
Dim tbl As Word.Table

GetDBPath = CurrentProject.Path 'nome percorso
dataf = Year(Me.data)
subfold = Format(Me.ID, "00")



CreateObject ("Word.Application")
On Error Resume Next 'gestione errori step by step 'cerca un'istanza di
Word già aperta
Set Wrd = GetObject(, "Word.Application")
If Err.Number = 429 Then 'se c'è stato un errore è perchè Word non era
già aperto: 'aprilo adesso
Set Wrd = CreateObject("Word.Application")
End If
On Error GoTo 0 'ripristina la segnalazione degli errori

Wrd.Visible = True
Wrd.Activate

Set Doc = Wrd.Documents.Add(CurrentProject.Path & "/rda.docx") 'nuovo doc
Set tbl = Doc.Tables(1)

Doc.Bookmarks("sottoscritto").Select
Wrd.Selection.TypeText Me.sottoscritto

Doc.Bookmarks("tipo").Select
Wrd.Selection.TypeText Me.tipo

Doc.Bookmarks("descrizione").Select
Wrd.Selection.TypeText Me.descrizione


i = 0
Me![sottomaschera item].SetFocus
DoCmd.GoToRecord , , acFirst

Do While IsNull(Forms!rda![sottomaschera item]!descrizione) = False

tbl.Cell(2 + i, 1).Select
Wrd.Selection.TypeText Forms!rda![sottomaschera item]!Qtà

tbl.Cell(2 + i, 2).Select
Wrd.Selection.TypeText Forms!rda![sottomaschera item]!descrizione

tbl.Cell(2 + i, 3).Select
Wrd.Selection.TypeText Forms!rda![sottomaschera item]!costo_unitario

tbl.Cell(2 + i, 4).Select
Wrd.Selection.TypeText Forms!rda![sottomaschera item]!importo_complessivo

i = i + 1

Me![sottomaschera item].SetFocus
DoCmd.GoToRecord , , acNext

Loop

Doc.Bookmarks("data").Select
Wrd.Selection.TypeText Me.data

'verifica presenza delle folder
If Len(Dir(GetDBPath & "\" & dataf, vbDirectory)) = 0 Then
MkDir GetDBPath & "\" & dataf
End If

If Len(Dir(GetDBPath & "\" & dataf & "\" & subfold, vbDirectory)) =
0 Then
MkDir GetDBPath & "\" & dataf & "\" & subfold
End If

new_modello = GetDBPath & "\" & dataf & "\" & subfold & "\" & subfold &
" - " & Me.descrizione & ".docx"
ActiveDocument.SaveAs2 (new_modello)

Doc.Close

Set Doc = Nothing
Set Wrd = Nothing
'Wrd.Quit
End Sub
0 new messages