0 Replies Latest reply on Mar 31, 2014 4:41 AM by randle1967

    Open Word Document in foreground when using VBScript

    randle1967

      Title

      Open Word Document in foreground when using VBScript

      Post

           Hi,

            

           I have a vbscript that opens a word document in read only format then populates several bookmarks and finally saves it with a different name and different folder. This works as I would like but the document does not open in the foreground, just in the taskbar. My operating system is Windows 8.1

            

           The following is my VBScript:

           "Set objWord = CreateObject('Word.Application')¶
           objWord.Visible = True¶
           Set objDoc = objWord.Documents.Open( 'C:\Dernier & Hamlyn Sales Database\Templates\Standard Order Acknowledgement.doc',,False)¶
           Set objRange = objDoc.Bookmarks('ContactName2').Range¶
           objRange.Text = '" & Entries::QuoteContact & "'¶
           Set objRange = objDoc.Bookmarks('ContactName').Range¶
           objRange.Text = '" & Entries::QuoteContact &"' ¶
           Set objRange = objDoc.Bookmarks('Company').Range¶
           objRange.Text = '" & Entries::CUSTOMER & "'¶
           Set objRange = objDoc.Bookmarks('InvoiceAddress').Range¶
           objRange.Text = '" & Entries::QuoteAddress1 & "'¶
           Set objRange = objDoc.Bookmarks('InvoiceAddress2').Range¶
           objRange.Text = '" & Entries::AddressL2 & "'¶
           Set objRange = objDoc.Bookmarks('InvoiceAddress3').Range¶
           objRange.Text = '" & Entries::AddressL3 & "'¶
           Set objRange = objDoc.Bookmarks('InvoiceAddress4').Range¶
           objRange.Text = '"  & Entries::AddressL4 & "'¶
           Set objRange = objDoc.Bookmarks('InvoiceAddress5').Range¶
           objRange.Text = '"  & Entries::AddressL5 & "'¶
           Set objRange = objDoc.Bookmarks('OrderNumber').Range¶
           objRange.Text = '"  & " "& Entries::CLIENT_ORD & "'¶
           Set objRange = objDoc.Bookmarks('OrderDate').Range¶
           objRange.Text = '" & " " & Globals::gPO Date & "'¶
           Set objRange = objDoc.Bookmarks('LeadTime').Range¶
           objRange.Text = '" & " " & Globals::gLead Time & "'¶
           Set objRange = objDoc.Bookmarks('Entry').Range¶
           objRange.Text = '" & Entries::ENTRY_NO & "'¶
           objDoc.SaveAs('" & $WordFilePath & "')¶
           ¶"
            
           I have tried adding objWord.Activate to the end of the coding but it just makes the word tile in the taskbar flash.
            
           Any help would be greatly appreciated.
            
           Kind regards, Mark.