|
-
Mar 17th, 2005, 11:52 AM
#1
Thread Starter
Hyperactive Member
{Resolved}Problem with Word-Bookmark with VB.NET
Hi,
This is the code I execute in a loop. For example ... this will be run 3-4 times to loop in a dataset.
VB Code:
objWord = CreateObject("Word.Application")
objWord.ActivePrinter = "My Printer Name"
objWord.Visible = False
Select Case strDocument
Case ANNEXEAF
With objWord
.Documents.Open("C:\Projets\\MyDocument.dot")
.ActiveDocument.Bookmarks.Item("siPOCKET").Select() 'word doc bookmark
.Selection.Text = clsClass.NoPermis
.ActiveDocument.Bookmarks.Item("siDATE").Select() 'word doc bookmark
.Selection.Text = clsClass.DateInfrac
.PrintOut(Copies:=1, Collate:=True, Background:=True, PrintToFile:=False)
'Wait for document to print
Do While .BackgroundPrintingStatus > 0
Application.DoEvents()
Loop
.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
End With
For the 1st document it's ok.
But then it kind of freeze. When I run it line by line (debugging), the application goes fine.
But if I'm not in debug mode, something is going wrong. The only thing I can see is the Do While .BackgroundPrintingStatus loop.
I have to move the mouse or do something else on my PC to make to program continue between each document to print.
And my application window "flikkles" .. as if we were seeing a Word window open, but I want that to happen in the background.
Thanks for helping !
Last edited by dbelley_office; Mar 18th, 2005 at 09:23 AM.
Reason: problem resolved.
-
Mar 17th, 2005, 12:41 PM
#2
Re: Problem with Word-Bookmark with VB.NET
Sounds like you would be better off making it a MailMerge type of document since all your doing is filling
bookmarks and printing. A MailMerge is a better choice for your needs?
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 
-
Mar 17th, 2005, 01:04 PM
#3
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
I don't really know how to do a MailMerge. Never done that before.
I can open a file template and put the value at specific location in my document with a mailmerge?
I my example I was filling bookmarks and printing. But some other times, I need to save to a .doc file instead of printing.
Would a MailMerger allow me to do that aswell ?
Know a good example on a website?
What is the big difference between a mailmerge and the way i was doing it?
Thanks.
Last edited by dbelley_office; Mar 17th, 2005 at 01:19 PM.
-
Mar 17th, 2005, 01:28 PM
#4
Re: Problem with Word-Bookmark with VB.NET
Not too much difference but the MM gives you better stability with bound fields versus bookmarks.
Also, you have four options for what to do with the document after its populated - email, fax, print, and save to file.
I was just helping another member on vb6 and a word mm in the vba forum. Same logic. I'll post the link in a minute.
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 
-
Mar 17th, 2005, 01:54 PM
#5
Re: Problem with Word-Bookmark with VB.NET
Here are two posts of mine from two threads dealing with automating a MM.
http://www.vbforums.com/showpost.php...70&postcount=6
http://www.vbforums.com/showpost.php...7&postcount=25
Note: these are both VB6 code examples.[/color]
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 
-
Mar 17th, 2005, 03:01 PM
#6
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
MM seems to work closely with datasource.
But I don't have a datasource.
On my VB form I have a listbox filled with the many person names.
I have a textbox for a date.
Lets say I have a myTemplate.dot file which contains the following text.
Mr. <myNAME>
The day of your interview is : <myDATE>
-----
So on my form when I click on PRINT.
I want, to make the merge with the data on my form and my word template.
I want to print a separate document for each names selected in the list.
But how can I make the link between the flags <myNAME> and <myDATE> ?
It was easy with the bookmark thing. But so slow between 2 documents.
-
Mar 17th, 2005, 03:20 PM
#7
Re: Problem with Word-Bookmark with VB.NET
Well, does the listbox get loaded from a datasource?
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 
-
Mar 17th, 2005, 03:35 PM
#8
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
The listbox yes.
But not the Date textbox. And that was only as example. On my true form there is 8-10 input fields.
-
Mar 17th, 2005, 03:38 PM
#9
Re: Problem with Word-Bookmark with VB.NET
Yes, then your better off with a word template document using bookmarks.
What happens if you close the document (in code) before the doc is done printing?
Maybe you could get rid of the loop?
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 
-
Mar 17th, 2005, 03:45 PM
#10
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
No I can't really get rid of the loop.
For my problem,
Using this code:
VB Code:
Do While objWord.BackgroundPrintingStatus > 0
' needs Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sleep (250) ' pause quarter second
Loop
Instead of this:
VB Code:
Do While objWord.BackgroundPrintingStatus > 0
Application.DoEvents()
Loop
Helps a lot for speed between document. Now it doesn't freeze.
But still ... I want this to happen in the background ... but I see a Word window showing for a very little while .. just very quickly flashing, but still I don't want that.
-
Mar 17th, 2005, 03:53 PM
#11
Re: Problem with Word-Bookmark with VB.NET
You could minimize Word in code so it wont flash.
Also, I was meaning what happens if you take out the loop completely? Does it error when your code try to close the document?
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 
-
Mar 17th, 2005, 04:05 PM
#12
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
See .. in the taskbar we see a Word window for like a quarter second. And my screen does as if it was too busy .. hard to refresh ..
I don't know if there is a way to avoid that.
The document doesn't print If I close it while it is in the queue.
-
Mar 17th, 2005, 04:08 PM
#13
Re: Problem with Word-Bookmark with VB.NET
Just before it prints set the Application.Visible = False and then when its done printing set it back to True.
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 
-
Mar 17th, 2005, 04:15 PM
#14
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
Application.Visible = False ?
What is "Application" ... my word?
Can't be more invisible than that.
VB Code:
objWord = CreateObject("Word.Application")
objWord.ActivePrinter = "TOSHIBA e-STUDIO16/20/25 PCL 6"
objWord.Visible = False
objWord.WindowState = Word.WdWindowState.wdWindowStateMinimize
.PrintOut(Copies:=1, Collate:=True, Background:=True, PrintToFile:=False)
-
Mar 17th, 2005, 04:20 PM
#15
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
The fact that Word is added a short while in the taskbar makes the screen to repaint .. that causes my form appearence problem.
I course printing 20 documents in a loop takes all the juice. But if I could avoid word to show up ... no repaint would occur and my WaitCursor would stay visible.
-
Mar 17th, 2005, 04:26 PM
#16
Re: Problem with Word-Bookmark with VB.NET
Word.Application.Visible
Since you are using the Selection object to replace the test in the bookmarks you can not keep word invisible for the complete duration.
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 
-
Mar 17th, 2005, 04:35 PM
#17
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
Really ?
When using bookmarks the Word window has to show up?
This is total crap then, who would want that. Especially when all example with bookmarks refers to background processing. I can't believe people accept that.
I will have to quickly find a backup idea for my application.
Thanks for your constant help.
-
Mar 17th, 2005, 04:51 PM
#18
Re: Problem with Word-Bookmark with VB.NET
Let me re-phrase that, you could use other techniques to fill in a bookmark other then the select method.
Try setting the .Text property of the bookmark to your clsClass.NoPermis directly instead of selecting/highlighting it.
VB Code:
.ActiveDocument.Bookmarks.Item("siPOCKET").Text = clsClass.NoPermis
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 
-
Mar 17th, 2005, 04:55 PM
#19
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
That property doesn't exist.
Would I avoid all these problem with a MM ?
I might want to change my processing steps and make a selection in the database for the word-fusion.
Last edited by dbelley_office; Mar 17th, 2005 at 05:00 PM.
-
Mar 17th, 2005, 04:59 PM
#20
Re: Problem with Word-Bookmark with VB.NET
Sorry, its under the range namespace.
VB Code:
.ActiveDocument.Bookmarks.Item("siPOCKET").Range.Text = clsClass.NoPermis
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 
-
Mar 17th, 2005, 05:18 PM
#21
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
Nah ! ..
Still had the same problem even doing this.
I have to go, but I will try to give a shot with MM later tonight only to see if it does the same when I print.
If not, i might try to modify my program to use a datasource in a fair way.
Thanks again for your ideas.
-
Mar 18th, 2005, 09:22 AM
#22
Thread Starter
Hyperactive Member
Re: Problem with Word-Bookmark with VB.NET
I finally found why I have the Word Window opening.
I had this:
VB Code:
objWord.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
objWord.Quit()
Now I have this
VB Code:
'objWord.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
objWord.Quit(Word.WdSaveOptions.wdDoNotSaveChanges)
It seems that closing a document without quiting word, makes the word application to show. Since the 2 lines were one after the other, that would explain why the word app was not really showing but just quickly flashing.
But now it works.
So it's better to Quit word with a DoNoSave then close a document with a DoNotSave and then Quit word.
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
|