-
HansV 966 Reputation points MVP
2021-01-21T10:33:29.223+00:00 The problem is that ActiveDocument does not refer to WrdApp. Change that line to
Set docActive = WrdApp.ActiveDocument
Error while moving from Excel to Word with VBA
Hello,
I´ve created a macro to export graphs from Excel to Word in an structured way, the code worked apparently well but today I´ve it has come up this recurrent error: "Run-time error '4248' This command is not available because no document is open" Actually the document is already open and regardless I activate the word doc manually in break-mode execution this error is still emerging.
Here is an extract of the code:
Sub ExportingToWord_MultipleCharts_Workbook()
'Declare Word Variables
Dim WrdApp As Word.Application
Dim WrdDoc As Word.Document
Dim SecCnt As Integer
Dim i As Integer, j As Integer
Dim docActive As Document
Dim tblNew As Table
Dim celTable As Table
Dim intCount As Integer
Dim tablerange As Word.Range
Dim rng As Word.Range
'Declare Excel Variables
Dim ChrtObj As ChartObject
Dim WrkSht As Worksheet
'Create a new instance of Word
Set WrdApp = New Word.Application
WrdApp.Visible = True
WrdApp.Activate
'Create a new word document
Set WrdDoc = WrdApp.Documents.Add
'Go back to Excel
Excel.Application.Visible = True
[...] Here it copies the corresponding graphs
'Go back to word
WrdApp.Visible = True
WrdApp.Activate
Set docActive = ActiveDocument (here is when the error emerges)
Set tblNew = docActive.Tables.Add(Range:=docActive.Range(Start:=0, End:=0), NumRows:=12, NumColumns:=1)
[....] More code
End Sub