Giri
06-15-2011, 03:18 AM
Hi Guys,
I have been trying to use VBA to open up a Word document. I wrote some code to do this while also checking to see whether Word was already open but I the result is that the code is continuously jumping to the MsgBox line...
Any help would be greatly appreciated!!
Option Explicit
Public Sub Giri()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim FileName As String
Dim myObject As Object
FileName = "C:\Users\Giridhaar\Desktop\Links.docx"
On Error Resume Next
Set myObject = GetObject(, "Word.Application")
If myObject Is Nothing Then
Set wrdApp = CreateObject("Word.Application")
wrdApp.Documents.Open FileName
Else
For Each wrdDoc In wrdApp
If StrComp(wrdDoc.FullName, FileName, vbTextCompare) = 0 Then
MsgBox "File already Open!"
Else
wrdApp.Documents.Open FileName
End If
Next wrdDoc
End If
End Sub
I have been trying to use VBA to open up a Word document. I wrote some code to do this while also checking to see whether Word was already open but I the result is that the code is continuously jumping to the MsgBox line...
Any help would be greatly appreciated!!
Option Explicit
Public Sub Giri()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim FileName As String
Dim myObject As Object
FileName = "C:\Users\Giridhaar\Desktop\Links.docx"
On Error Resume Next
Set myObject = GetObject(, "Word.Application")
If myObject Is Nothing Then
Set wrdApp = CreateObject("Word.Application")
wrdApp.Documents.Open FileName
Else
For Each wrdDoc In wrdApp
If StrComp(wrdDoc.FullName, FileName, vbTextCompare) = 0 Then
MsgBox "File already Open!"
Else
wrdApp.Documents.Open FileName
End If
Next wrdDoc
End If
End Sub