![](/uploads/1/2/5/3/125386602/851369663.jpg)
I'm trying to copy a selection to a new document and then export it to PDF, but I'm getting an error that I cannot resolve.
You can paste a chart into Word and link it to its source file. If you do that, whenever you make a change in the source Excel file, Word can update the chart in your document to reflect the changes in the source Excel file. To link your chart to its source you need the Paste Special dialog. Mar 30, 2008 To insert a chart, you must first close any open dialog boxes or cancel editing mode in Microsoft Office Excel Help! I am trying to create a chart in Office 07 professional version and although I had no dialog boxes open in word processing, I received this message. How to insert a chart you must first close any open dialog boxes or cancel.
On the line
ActiveWindow.Close False
I'm being toldRun-time error '5479':
You cannot close Microsoft Word because a dialog box is open. Click OK, switch to word and then close the dialog box.
You cannot close Microsoft Word because a dialog box is open. Click OK, switch to word and then close the dialog box.
Unless the export to PDF operation is firing up a dialog, I do not know what dialog would be open.
Can anyone please shed some light? Thanks.
David GardDavid Gard4,7692121 gold badges6767 silver badges138138 bronze badges
2 Answers
It should be
BugsActiveDocument.Close
instead of ActiveWindow.Close
.4,17099 gold badges2727 silver badges3737 bronze badges
cbodencboden
Especially when working with multiple files, it's a best practice to use object variables to represent the files, so that you have an easier handle on them and don't need to try and remember which is Active at any particular time, you can just refer to the object directly.
For your specific problem, make sure you are closing the Document, not the Window.
![Dialog Dialog](/uploads/1/2/5/3/125386602/631490461.jpg)
NB: it's usually recommended to avoid relying on
David ZemensDavid ZemensActivate
and Select
methods (this explains it in detail). Of course this is not as possible to avoid the Selection
in Word, but the broader point remains that avoiding it when possible will lead to better code that's easier to read and maintain in the future.45.9k1010 gold badges5454 silver badges104104 bronze badges
Not the answer you're looking for? Browse other questions tagged vbaword-vbaword-2010 or ask your own question.
![](/uploads/1/2/5/3/125386602/851369663.jpg)