Microsoft Word - Run time error 5479 in VB macro

Asked By sugi krishna
13-Dec-11 02:25 AM
Hi,
I am getting run time error 5479 with the below code.

  Set LetterTemplate = Word.Documents.Open(LetterDocPath)

It gives Debug option, and if i simply move the cursor to the next line and run it again, the VB macro finishes fine.
This error happens only when I run the macro via a word doc, if i run the Normal file itself, there is no error.

Please can you guide us the solution,
  dipa ahuja replied to sugi krishna
  sugi krishna replied to dipa ahuja
13-Dec-11 03:37 AM
Hi,
I did go through that , but my problem is though I have added the global template on my word, it still throws error 5479.

I also tried error handling such as

On Error Resume Next, but dint work out.

Please can you help.
  Anoop S replied to sugi krishna
13-Dec-11 04:11 AM
This will not happen if:
you do not have a clean Document1 created by opening word, type something in Document1 - OK, Create Document2, close Document1 - OK, close Document1 (leaving no documents open) - OK,  do not load the template globally but run from the open template

It will go away with:
Me.hide
Documents.Open FileName:=sFile
Me.show
  sugi krishna replied to Vickey F
13-Dec-11 04:18 AM
Hi Vickey,
I did try the suggestions mentioned in the posts about display Alerts as None, but still no luck.

My code is as below, can you suggest please.

 LetterDocPath = sGetINI(sINIFile, "DirectoryPaths", "CWC_LETER_DOC_PATH", "")
          Set LetterTemplate = Word.Documents.Open(LetterDocPath)
Application.DisplayAlerts = wdAlertsNone
On Error Resume Next
With ActiveDocument
    .Bookmarks("CustomerName").Range.Text = tbCustName
              If obBillingAddress = True Then
                .Bookmarks("MailingAddress").Range.Text = tbBillingAddress
              ElseIf obPropertyAddress = True Then
                .Bookmarks("MailingAddress").Range.Text = tbPropertyAddress
              End If
  If fs.FileExists(strFile) Then
              Call InsertSuggestedText
            End If
          

           strOurreference = tbRefNoValue
            strtitle = Strings.UCase(tbLetterTitle)
            FilePath = tbFilePath.Text
           ' If MsgBox("Clicking Ok will enable you to proceed with the saved letter", vbOKCancel) = vbOK Then
            Call SaveDocument(strOurreference, strtitle, FilePath)
            'Unload Me
Me.Hide
          '  Else
           ' End If
          End If
  sugi krishna replied to Anoop S
13-Dec-11 04:33 AM
Hi Anoop,
I tried with Me.hide, then the document.open and then Me.show, but in that case nothing progresses and the same form repeats.

This macro is used by users, so I usually add the normal.dot under Tools->Options->FileLocations and ask the users to open a new word doc and run the macro.
Now this does not work, but if i run the normal.dot itself, it works all ok.
  Manish Mishra replied to sugi krishna
16-Dec-11 05:35 AM
Hi,
Try the following and let me know if this works.
1. create a short - cut key for your macro on normal.dot
2. create your macro on a module instead of "ThisDocument" in your normal.dot
3. also check if your code line "Set LetterTemplate = Word.Documents.Open(LetterDocPath)" gets the path access.


Create New Account
help
Microsoft Word 2007 hangs and does not close properly on 2007 Word Word 2007 does not close properly and hangs everytime. I have to 'close program" and windows diagnostics does not seem to find any errors Word Application Errors Discussions Microsoft Word (1) Windows Vista (1) Word 2007 (1) Office (1) FixIt
How do i extract a document from word 2003 to word 2007? Word I recently upgraded to microsoft word 2007- How do i open my documents from word 2003? Word Document Management Discussions Microsoft Word (1) Word 2007 (1) Word 2003 (1) Office
Microsoft Word 2007 Word I have done something to my Microsoft Word 2007 program that has caused me alot of stress. I have used this program for 3 years without difficulties. In the last week I did something to make the Word program "redo the original settings." When I open up Microsoft Word 2007, the indentation was
How can I insert a "Microsoft Word Picture" object with Word 2007? Word I can edit a "Microsoft Word Picture" object with Word 2007 in a document created with Word 2003 but I do not know how to
Word 2007 Menu Word I have the new Microsoft 2007 Word version. I am use to the old menu look. How can I have the old menu look in Microsoft Word 2007 (Classic look- - FILE, EDIT, etc. . .) Thank you, Word Menus Toolbars Discussions Microsoft Word (1