|
-
May 20th, 2005, 10:53 AM
#1
Thread Starter
Junior Member
problem during printing word doc from vb
I've used bookmarked msword from my vb application to print documents.
after printing
Dim wordapp As New Word.Application
Dim thisdoc As New Word.Document
Set wordapp = Nothing
Set thisdoc = Nothing
Set thisdoc = wordapp.Documents.Open("D:\I B A PRODUCT\Manual Joining Letter.doc", ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", Format:=wdOpenFormatAuto)
'temp_name comes from a database table
If thisdoc.Bookmarks.Exists("name1") = True Then
thisdoc.Bookmarks("name1").Select
' wordapp.ActiveDocument.Bookmarks("name1").Start
wordapp.Selection.TypeText temp_name
End If
wordapp.ActiveDocument.PrintOut Range:=wdPrintCurrentPage
intmsg = MsgBox("Did the document print correctly", vbYesNo)
If intmsg = vbNo Then
intmsg = MsgBox("Do you want to try again printing join details?", vbYesNo)
If intmsg = vbYes Then
wordapp.Documents.Close (wdDoNotSaveChanges)
wordapp.Quit
end if
but after certain no of printing windows virtual memory becomes low as i can see in the task manager several no of winword.exe which are feeling up the memory.
Is there any way to free memory and destroy winword.exe from memory as soon as the printing is complete!
-
May 21st, 2005, 09:22 AM
#2
Re: problem during printing word doc from vb
try after wordapp.quit
set wordapp = nothing
set thisdoc = nothing
pete
-
May 21st, 2005, 09:38 AM
#3
Re: problem during printing word doc from vb
Also, thisdoc.Close. By using the "wordapp.Documents.Close (wdDoNotSaveChanges)" you are not closing and
destroying the thisdoc object. This is the main issue most office developers miss and end up with multiple instances of their office app.
Are you calling this code every time you print? If so you can optimise it by only opening, printing, and closing the document. Move
your app object to the general declarations section to the top. Then upon loading of your app you open the word app and keep it hidden if needed.
Then upon button click you only need to open the doc, etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|