Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Am I doing something silly?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy - 21 Nov 2005 22:45 GMT
Hi,
I've just posted a similar Q below to do with word2000, but in the long run
I need to get this going with word2003.

Basically I get an error when programatically openning a word doc which
contains macros when DisplayAlerts are set to none (wdAlertsNone) and macros
are dissabled  (msoAutomationSecurityForceDisable). Is there any way around
this? I thought that the idea of DisplayAlerts was to get around the
errors... I want to be able to open a word doc programatically (from a
server) and so don't want error messages...

I get the following error, and beneath is the VB.net code (basics only). I
hope someone can help as its doing my head in!

Thanks xx

Error:
'Title - Microsoft Visual Basic
'Text - The macros in this project are disabled. Please refer to the online
help or documentation of the host application to determine how to handle
macros.

Private Function BasicOpenWord(ByVal WordDocPath As String) As Boolean
Dim oWordApp As New Word.Application
Try
    oWordApp.Visible = false
    oWordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone'Don't want ANY alerts
    'IF we open the doc with just the above, there is nothing to stop macros
running.
    'When an app is started its default is msoAutomationSecurityLow -low
security. So...
    Dim secAutomation As MsoAutomationSecurity
   

    With oWordApp
        secAutomation = .AutomationSecurity
        .DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
        .AutomationSecurity =
oWordApp.AutomationSecurity.msoAutomationSecurityForceDisable
   
        '#### You will get the following error on the next line : #####
        .Documents.Open( _
        FileName:=WordDocPath.ToString, _
        ConfirmConversions:=False, _
        ReadOnly:=True, _
        AddToRecentFiles:=False, _
        Format:=Word.WdOpenFormat.wdOpenFormatAuto)
    .AutomationSecurity = secAutomation
    End With

    oWordApp.Documents.Close()
    BasicOpenWord = True
Catch ex As Exception
    ...
    BasicOpenWord = False
Finally
    oWordApp.Quit()
    oWordApp = Nothing
End Try
End Function
zkid - 22 Nov 2005 21:41 GMT
Do you get the same message when you open the document manually?

If so, 2003 is a little strange that way.  Sometimes you have to open your
docs/templates in 2003, make sure your reference libraries, if any, are
connected properly, and then save the document.

> Hi,
> I've just posted a similar Q below to do with word2000, but in the long run
[quoted text clipped - 56 lines]
> End Try
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.