Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-17-2011, 09:12 AM
Jaymond Flurrie Jaymond Flurrie is offline Clear document Windows 7 64bit Clear document Office 2010 32bit
Novice
Clear document
 
Join Date: Feb 2011
Posts: 13
Jaymond Flurrie is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 07-17-2011, 10:11 AM
Jaymond Flurrie Jaymond Flurrie is offline Clear document Windows 7 64bit Clear document Office 2010 32bit
Novice
Clear document
 
Join Date: Feb 2011
Posts: 13
Jaymond Flurrie is on a distinguished road
Default

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
That first paste doesn't work, the next works fine. The error it gives is Run-time error '5342': The specified datatype is unavailable. Seems to me something is wrong with using that wdPasteMetafilePicture, but what?
Reply With Quote
  #3  
Old 07-17-2011, 04:58 PM
macropod's Avatar
macropod macropod is offline Clear document Windows 7 64bit Clear document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #4  
Old 07-17-2011, 05:02 PM
Jaymond Flurrie Jaymond Flurrie is offline Clear document Windows 7 64bit Clear document Office 2010 32bit
Novice
Clear document
 
Join Date: Feb 2011
Posts: 13
Jaymond Flurrie is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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'.
I'll check this "3" in a while, but shortly, the reason I'm using Word is that when I want to print a PDF with six charts with each on it's own page, I have absolutely no idea how to do it with Excel - first page is easy, but I have no idea how to print the second page into the same file, so I decided instead to work with Word in between.
Reply With Quote
  #5  
Old 07-17-2011, 05:05 PM
macropod's Avatar
macropod macropod is offline Clear document Windows 7 64bit Clear document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Jaymond,
Quote:
I want to print a PDF with six charts with each on it's own page, I have absolutely no idea how to do it with Excel - first page is easy, but I have no idea how to print the second page into the same file
Simple: put all the charts on the same worksheet, with page breaks between them.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 07-17-2011, 05:07 PM
Jaymond Flurrie Jaymond Flurrie is offline Clear document Windows 7 64bit Clear document Office 2010 32bit
Novice
Clear document
 
Join Date: Feb 2011
Posts: 13
Jaymond Flurrie is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Hi Jaymond,

Simple: put all the charts on the same worksheet, with page breaks between them.
Darn it with you experts, always ruining the hard work with some simplest possible answer

Thanks!
Reply With Quote
Reply



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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft