![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hello,
I'm using the following code to open a word document saved on a network drive Sub label105_click Set Word = CreateObject("Word.Application") Word.Visible = TRUE Word.Documents.open("G:\whatever.dot") End Sub I've been assured that almost everyone in the company has access to the G:\ - however I'd like to make a message box appear if Word can't access the document - something like "Please contact IT to map your G:\" Can I just alter the code so it states.... Sub label105_click Set Word = CreateObject("Word.Application") Word.Visible = TRUE Word.Documents.open("G:\whatever.dot") If Word.Documents.open Is Nothing Then MsgBox "Please contact IT to map your G:\" Else End Sub |
Ads |
#2
|
|||
|
|||
![]()
That's close, but you need to explicitly return the Document object from the Open method:
On Error Resume Next Set doc = Word.Documents.open("G:\whatever.dot") If doc Is Nothing Then MsgBox "Please contact IT to map your G:\" Else ' do stuff with doc End If -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx wrote in message oups.com... Hello, I'm using the following code to open a word document saved on a network drive Sub label105_click Set Word = CreateObject("Word.Application") Word.Visible = TRUE Word.Documents.open("G:\whatever.dot") End Sub I've been assured that almost everyone in the company has access to the G:\ - however I'd like to make a message box appear if Word can't access the document - something like "Please contact IT to map your G:\" Can I just alter the code so it states.... Sub label105_click Set Word = CreateObject("Word.Application") Word.Visible = TRUE Word.Documents.open("G:\whatever.dot") If Word.Documents.open Is Nothing Then MsgBox "Please contact IT to map your G:\" Else End Sub |
#3
|
|||
|
|||
![]()
In article .com,
wrote: Sub label105_click Set Word = CreateObject("Word.Application") Word.Visible = TRUE Word.Documents.open("G:\whatever.dot") If Word.Documents.open Is Nothing Then MsgBox "Please contact IT to map your G:\" Else End Sub If I read the code naively, then the last open on "Word.Documents.open" is a method, not an object. So, this line should throw an error to the effect that no document is found. And really, you have created a world of confusion for yourself by naming your Word Application Object "Word". You should be using naming practices to make clear what the objects are in lines of code removed from where you create them. So, you should use something line the following for the first object: Set myWordApp = CreateObject("Word.Application") and you should test that object to see if you created it. Then, if Word were structured like Outlook, and it really isn't, you would have to create a Documents collection object. But, in looking quickly through my last custom form using Word Documents, I find where the document object is created, and the next thing I see is where a template is added: myWordApp.Documents.Add strWordTemplate myWordApp.Visible = True myWordDoc = myWordApp.ActiveDocument In any case, I think you need to find an example of working with Word documents through Outlook, set up a VBA project, set references to the several Word object models, and get creative with the Object Browser (F2) to find the names of the objects you need to use, and the name of the methods you will have to use, and find out what each does. This is no easy task for a hard day's night's burning of the midnight oil. It will probably take several weeks. Be sure and tell your supervisor so time will be allocated for the task. I think you can find a relevant code example on www.outlookcode.com . I found my starter example on an old, old web-site, and I would not recommend anyone else go that route. -- Hollis Paul Mukilteo, WA USA |
#4
|
|||
|
|||
![]()
Thanks for your reply Hollis. I'm a bit of a newbie when it comes to VB
code. As I'm successfully using the basic code without the error message box, I thought it would be an easy case of adding something like "if there's an error in opening the document, then display this message" however it all looks a bit more complicated than I imagined. If there isn't a simple 'if error, then msgbox' code fix then I think I'll leave the code alone. Thanks again. |
#5
|
|||
|
|||
![]()
Thanks Sue,
I'm now using the following code: Sub label105_click Set Word = CreateObject("Word.Application") Word.Visible = TRUE Word.Documents.open("G:\whatever.dot") On Error Resume Next Set doc = Word.Documents.open("G:\whatever.dot") If doc Is Nothing Then MsgBox "Please contact IT to map your G:\" Else End If I trust that it will work (My testing is limited as I can't upload the form to the public drive - and our IT department get a bit narky with me when I keep asking them to re-upload the form). |
#6
|
|||
|
|||
![]()
You'll want to put that On Error Resume Next as the first line in the Sub.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx wrote in message oups.com... Thanks Sue, I'm now using the following code: Sub label105_click Set Word = CreateObject("Word.Application") Word.Visible = TRUE Word.Documents.open("G:\whatever.dot") On Error Resume Next Set doc = Word.Documents.open("G:\whatever.dot") If doc Is Nothing Then MsgBox "Please contact IT to map your G:\" Else End If I trust that it will work (My testing is limited as I can't upload the form to the public drive - and our IT department get a bit narky with me when I keep asking them to re-upload the form). |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
customising calendar print view... | Ian R | Outlook - Calandaring | 0 | May 18th 06 01:48 PM |
Problem customising display of Outlook 2003 Calendar | SHPA7 | Outlook - Calandaring | 1 | February 12th 06 10:45 PM |
Customising a contacts form | Kim | Outlook - Using Contacts | 1 | February 2nd 06 04:35 PM |
Customising Forms | [email protected] | Outlook - Using Forms | 1 | January 31st 06 02:04 PM |
Customising the (GAL) Outlook addressbook | C.Davis | Outlook - Using Contacts | 1 | January 18th 06 06:00 PM |