Microsoft Word - Run time error 5479 in VB macro

Asked By sugi krishna on 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 on 13-Dec-11 02:53 AM
sugi krishna replied to dipa ahuja on 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 on 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 Jitendra Faye on 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 on 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 on 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.