#1
|
|||
|
|||
Clear document
Hi,
This is next to "Hello World" for you who have programmed Word even a bit. Short and simply: How do I clear the document? The bigger idea is that I'm importing data from Excel to Word and I used to have my flow going basically like this: Create Word application Create Word document Select the header Edit the header Select the "main part" of document Type text { Paste a chart Enter PageBreak }(Repeat five times) Paste a chart Print to PDF Close the document without saving Terminate the instance of Word With six charts, forty documents it took about three minutes. Now I realized that it's pretty stupid to create the Word application and Word document from scratch over and over again. Smarter solution would be just to delete everything from the document and close/terminate it at the end. Sure, I could also create a new document each time, but since I don't need the docs (the only reason I use Word at all is that it compiles the document nicely), I don't know if it would be any faster to create a new document. If you know for sure that just closing the old and creating a new document is faster than deleting the whole content is faster, please tell me. Even better might be linking system ie. I create the document by pasting once and then updating the charts in Excel updates them in Word and then I take a printout. Is that possible? |
#2
|
|||
|
|||
I tried that later part, just by pasting a link:
Code:
With appWD.Selection .MoveRight Unit:=wdCharacter, Count:=1 .TypeText Text:="Left part of header" .ParagraphFormat.Alignment = wdAlignParagraphLeft .TypeText Text:=vbTab & vbTab & "right part of header" DocWD.Parent.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument strChartName = "A. header" shtCharts.Shapes(strChartName).Copy .TypeText Text:=vbTab & vbTab & vbTab & vbTab & strChartName & vbCrLf .Font.Bold = wdToggle .PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False .InsertBreak Type:=wdPageBreak strChartName = "B. header" shtCharts.Shapes(strChartName).Copy .TypeText Text:=vbTab & vbTab & vbTab & vbTab & strChartName & vbCrLf .Font.Bold = wdToggle .PasteSpecial Link:=True, DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False .InsertBreak Type:=wdPageBreak End With |
#3
|
||||
|
||||
Hi Jaymond,
I have to wonder why you're bothering to use Word at all. From what you've described, it seems to me the lot could be done within Excel. In any event, to do it in Word, you don't have to select anything - simply tell it which range(s) to work with. As for the run-time error, that'll occur if you're using late binding. Try using '3' instead of 'wdPasteMetafilePicture'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Quote:
|
#5
|
||||
|
||||
Hi Jaymond,
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Quote:
Thanks! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Trying to clear the background colour from a theme | ezekiel181 | Word | 1 | 11-14-2010 07:29 AM |
Search and Replace - Clear Search box | JostClan | Word | 1 | 05-04-2010 08:46 PM |
command clear forms | dmcohio | Word | 0 | 04-08-2010 11:11 AM |
'Clear formatting' issue | phoebs47 | Word | 0 | 03-16-2010 06:55 AM |
Holidays--clear all? | markg2 | Outlook | 0 | 11-01-2009 05:57 AM |