Results 1 to 3 of 3

Thread: problem during printing word doc from vb

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    17

    Exclamation 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!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: problem during printing word doc from vb

    try after wordapp.quit
    set wordapp = nothing
    set thisdoc = nothing


    pete

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width