ciao a tutti io avrei bisogno di generare e salvare un file word (con access) utilizzando un modello *.dot di riferimento.
Ho provato cosi' ma mi da errore sulla saveas.
qualcuno saprebbe dirmi che c'eč che non va?
Dim word 'the Word application
Dim doc 'the Word document
Dim selection 'text selection
Dim fs 'the File system
Dim work_dir 'the directory for storing files
Dim folder, folders 'used when creating the new file
Dim I, j 'indexes for arrays
Dim Nix As Variant
Dim modello As String
Dim nomefile As String
Dim ReplSel As Boolean
Dim fld As DAO.Field
modello = "c:\MODELLO.dot"
nomefile = "C:\test.doc"
Set word = CreateObject("word.application")
Set fs = CreateObject("Scripting.FileSystemObject")
Dim nameuser
nameuser = "test.doc"
work_dir = "C:\"
Set doc = word.Documents.Add(modello)
Set selection = word.selection
'selection.TypeText "An Automated Word Report"
'selection.TypeParagraph
If Not fs.folderexists(work_dir) Then
folders = Split(work_dir, "\")
For I = 0 To UBound(folders) - 1
folder = ""
For j = 0 To I
folder = folder & folders(j) & "\"
Next
If Not fs.folderexists(folder) Then
fs.createfolder folder
End If
Next
End If
If Len(Trim(Nz(nameuser))) = 0 Then
Nix = MsgBox("No valid filename", vbCritical, "Cancel")
Exit Sub
Else
If File_exist(work_dir & nameuser) Then
Nix = MsgBox("Il file e' gia' presente" & _
vbCrLf & "nome del file : " & work_dir & nameuser & vbCrLf & _
"vuoi sovrascrivere il file ?", _
vbYesNo + vbCritical, "WinWord - file aready exists")
If Nix = vbNo Then
Exit Sub
End If
End If
End If
word.Visible = True
'doc.SaveAs (work_dir & nameuser)
doc.SaveAs (nomefile)
'word.Quit
Set fs = Nothing
Set word = Nothing
'Dim oApp As Object
'Set oApp = CreateObject("Word.Application")
'oApp.Visible = True
'oApp.Documents.Add DocumentType:=wdNewBlankDocument
End Sub
grazie per l'attenzione
Ricky