Cześć,
jestem początkujący w VBA. Chciałbym napisać marko, które będzie umożliwiało przepisanie danych z formularza Excel do Worda, gdzie zdefiniowałem pola zmienne z użyciem zakładek. Poniżej mój kod, po jego wciśnięciu wyskakuje mi błąd "Run-time error "1004": Application-defined or object-defined error. Czy możecie wskazać co jest nie tak?
Option Explicit
Sub exportToWord()
Dim WordApp As New Word.Application
Dim doc As Word.Document
Dim rng_full_name As Word.Range
Dim full_name As Word.Range
Dim transaction As Word.Range
Dim period As Word.Range
Dim docPath As String, expoPath As String
Dim outFilePath As String
expoPath = Range("OutputPath").Value & Range("New_Report").Value & ".docx"
WordApp.Visible = True
Set doc = WordApp.Documents.Open([wordPath].Text, , True)
Set full_name = doc.Bookmarks("full_name").Range
full_name.Text = Range("full_name").Value
full_name.Font.Bold = True
Set transaction = doc.Bookmarks("transaction").Range
transaction.Text = Range("transaction").Value
Set period = doc.Bookmarks("period").Range
period.Text = Range("period").Value
Set full_name = Nothing
Set transaction = Nothing
Set period = Nothing
doc.Close
doc.ExportAsFixedFormat expoPath, wdExportFormatXPS
Set doc = Nothing
End Sub
Private Sub Workbook_Open()
End Sub