Devagorgon
New Member
- Joined
- Sep 25, 2018
- Messages
- 13
I have to write a macro in Excel VBA to convert a given Excel Document into a word file.
So far I have managed most of the normal copying starting like this
Dim oConvWB As Workbook
Set oConvWB = Workbooks.Open(TextBox_ExcelPath.Text)
Dim AppWord As Object
Set AppWord = CreateObject("Word.Application")
Set AppWdDoc = AppWord.Documents.Add
AppWord.Visible = True
I copy the normal content via
oConvWB.Sheets("S1 Deckblat").Select
oConvWB.Sheets("S1 Deckblat").Range(Cells(18, 1), Cells(43, 8)).Copy
AppWord.Selection.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=True
The Problem ist, that I have some selected content, I need to write into Header and Footnotes (different for first and later pages) and I cannot find any working (paste- or accessing-) commands.
Using commands like
Dim HdrRange As Range
Set HdrRange = AppWdDoc.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
will crash at the Set command
Even just manipulating the Header Text via
AppWord.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Text"
fails with an error.
If someone could tell me, how I can insert text (or even better, how I can paste my selected Cells from Excel), I'd be grateful.
So far I have managed most of the normal copying starting like this
Dim oConvWB As Workbook
Set oConvWB = Workbooks.Open(TextBox_ExcelPath.Text)
Dim AppWord As Object
Set AppWord = CreateObject("Word.Application")
Set AppWdDoc = AppWord.Documents.Add
AppWord.Visible = True
I copy the normal content via
oConvWB.Sheets("S1 Deckblat").Select
oConvWB.Sheets("S1 Deckblat").Range(Cells(18, 1), Cells(43, 8)).Copy
AppWord.Selection.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=True
The Problem ist, that I have some selected content, I need to write into Header and Footnotes (different for first and later pages) and I cannot find any working (paste- or accessing-) commands.
Using commands like
Dim HdrRange As Range
Set HdrRange = AppWdDoc.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
will crash at the Set command
Even just manipulating the Header Text via
AppWord.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Text"
fails with an error.
If someone could tell me, how I can insert text (or even better, how I can paste my selected Cells from Excel), I'd be grateful.