Originariamente inviato da ghini76
Dovrei modificare un file Word (.doc) da Vb6.
Ho provato a fare una ricerca nel forum ma il motore è disattivato.
Potete darmi qualche dritta su come usare la libreria Word?
Ciao e grazie
devi crearti prima di tutto un'istanza di word
codice:
Global Const GWL_STYLE = (-16)
Global Const ES_NUMBER = &H2000&
Global WordApp As New Word.Application
Global WordDoc As New Word.Document
Global wSelection As Word.Selection
Global wMailMerge As Word.MailMerge
Global wMergeFields As Word.MailMergeFields
Global Word_was_running As Boolean
e poi gestirla da codice ad esempio io hjo fatto una stampa unione
questa funzione ti gestisce eventuali errori
codice:
Function StartaWord(ByVal TemplateFile As String) As Boolean
On Error GoTo ErrInizio
Set WordApp = GetObject(, "Word.Application")
WordApp.Documents.Open App.Path & "\Modelli\" & TemplateFile
Word_was_running = True
StartaWord = True
'se vuoi vedere word fai questo
'WordApp.Visible = True
On Error GoTo 0
Exit Function
Err1:
On Error GoTo ErrStartaWord
Set WordApp = CreateObject("word.Application")
WordApp.Documents.Open App.Path & "\Modelli\" & TemplateFile
Word_was_running = False
StartaWord = True
On Error GoTo 0
Exit Function
ErrInizio:
If Err.Number = 429 And (Err.Description = "ActiveX component can't create object" Or _
Err.Description = "Il componente ActiveX non può creare l'oggetto") Then
'probabilmente word non è avviato, quindi lo creo
Err.Clear
GoTo Err1
Else
Print #1, Err.Number & " - " & Err.Description & " (StartWord) - " & Date & " - " & Time
End If
On Error GoTo 0
Exit Function
ErrStartaWord:
Print #1, Err.Number & " - " & Err.Description & " (StartWord) - " & Date & " - " & Time
End Function