Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

how to get the path of the current word file opened using MS WORD..in VB

Hi all
my question is :
How to find the path of the current word file that has been opened using the MS WORD...
i want to do this using VB...
is there any win32 api function available for this..
i am ready to give away a lot of points for this..
Nitin
0
khacharn
Asked:
khacharn
  • 11
  • 7
  • 3
  • +1
1 Solution
 
WolfgangKoenigCommented:
This is easy:
When you opened word as ole and you have the object
mywordapp:
Dim FilePath As String

FilePath = mywordapp.ActiveDocument.FullName

Hope this helps
Wok
0
 
TimCotteeCommented:
Use the following code:

Private Sub Command1_Click()
Dim appWord As Object
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If appWord Is Nothing Then
  MsgBox "There is no active Word Session"
Else
  MsgBox appWord.ActiveDocument.fullName
End If
End Sub

This retrieves the open word session and gets the fullname of the activedocument.
0
 
WolfgangKoenigCommented:
Add on:
With the property Path of the object Document you can
get only get the dir path of the file:
DirPath = mywordapp.ActiveDocument.Path

and with the property Name of the object Document you can
get only the filename without a dir path:
FileName = mywordapp.ActiveDocument.Name

Best regards
WoK



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nvivasCommented:
u can use API's as well... here's some code:
(it works for EXCEL and for other applications as well!)

Private Const SW_HIDE = 0
Private Const SW_SHOWNORMAL = 1
Private Const SW_NORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_RESTORE = 9
Private Const SW_SHOWDEFAULT = 10
Private Const SW_MAX = 10



Private Declare Function apiFindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal strClass As String, _
    ByVal lpWindow As String) As Long

Private Declare Function apiSendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal Hwnd As Long, ByVal Msg As Long, ByVal _
    wParam As Long, lParam As Long) As Long
   
Private Declare Function apiSetForegroundWindow Lib "user32" Alias _
    "SetForegroundWindow" (ByVal Hwnd As Long) As Long
   
Private Declare Function apiShowWindow Lib "user32" Alias _
    "ShowWindow" (ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long
   
Private Declare Function apiIsIconic Lib "user32" Alias _
    "IsIconic" (ByVal Hwnd As Long) As Long
   
Function fIsAppRunning(ByVal strAppName As String, _
        Optional fActivate As Boolean) As Boolean
    Dim lngH As Long, strClassName As String
    Dim lngX As Long, lngTmp As Long
    Const WM_USER = 1024
    On Local Error GoTo fIsAppRunning_Err
    fIsAppRunning = False
    Select Case LCase$(strAppName)
        Case "excel":       strClassName = "XLMain"
        Case "word":        strClassName = "OpusApp"
        Case "access":      strClassName = "OMain"
        Case "powerpoint95": strClassName = "PP7FrameClass"
        Case "powerpoint97": strClassName = "PP97FrameClass"
        Case "notepad":     strClassName = "NOTEPAD"
        Case "paintbrush":  strClassName = "pbParent"
        Case "wordpad":     strClassName = "WordPadClass"
        Case Else:          strClassName = ""
    End Select
   
    If strClassName = "" Then
        lngH = apiFindWindow(vbNullString, strAppName)
    Else
        lngH = apiFindWindow(strClassName, vbNullString)
    End If
    If lngH <> 0 Then
        apiSendMessage lngH, WM_USER + 18, 0, 0
        lngX = apiIsIconic(lngH)
        If lngX <> 0 Then
            lngTmp = apiShowWindow(lngH, SW_SHOWNORMAL)
        End If
        If fActivate Then
            lngTmp = apiSetForegroundWindow(lngH)
        End If
        fIsAppRunning = True
    End If
fIsAppRunning_Exit:
    Exit Function
fIsAppRunning_Err:
    fIsAppRunning = False
    Resume fIsAppRunning_Exit
End Function
0
 
khacharnAuthor Commented:
Thanx for all the help people...
it has helped me a lot..
one more thing please...
what should i do to find out the current adobe file opened using Adobe Acrobat reader..
i don't mind increasing the points..for this..
Best Regards
Nitin
0
 
khacharnAuthor Commented:
can someone please give me some resource or listing of all the properties like
mywordapp.ActiveDocument.Path
that is all the properties i can list for a particular docuement which is open..
i am also waiting for some solution for getting the ADODE document opened using ADOBE ACROBAT READER..
please help soon
Best Regards
Nitin
0
 
WolfgangKoenigCommented:
To view all properties:
Call in word the visual basic editor (also macro editor)
with mousebar "visual basic".
When you are in the VBE then open an code plane and
click the right mouse button to invoke the "object catalog".
When you in the object catalog choose the class "Document" and press then the F1 key for invoking the help for the object. There you find all methods and properties.

(points?)
WoK
0
 
khacharnAuthor Commented:
can someone please give me some resource or listing of all the properties like
mywordapp.ActiveDocument.Path
that is all the properties i can list for a particular docuement which is open..
i am also waiting for some solution for getting the ADODE document opened using ADOBE ACROBAT READER..
please help soon
Best Regards
Nitin
0
 
WolfgangKoenigCommented:
You can also use the "View" menu in the VBE to open the object catalog ...
0
 
khacharnAuthor Commented:
can someone please give me some resource or listing of all the properties like
mywordapp.ActiveDocument.Path
that is all the properties i can list for a particular docuement which is open..
i am also waiting for some solution for getting the ADODE document opened using ADOBE ACROBAT READER..
please help soon
Best Regards
Nitin
0
 
WolfgangKoenigCommented:
You can also use the "View" menu in the VBE to open the object catalog ...
0
 
khacharnAuthor Commented:
can someone please give me some resource or listing of all the properties like
mywordapp.ActiveDocument.Path
that is all the properties i can list for a particular docuement which is open..
i am also waiting for some solution for getting the ADODE document opened using ADOBE ACROBAT READER..
please help soon
Best Regards
Nitin
0
 
khacharnAuthor Commented:
WolfgangKoenig
I need to know how to get the current Adobe document path...can you help me in this please...
don't mind increasing the points to a bit more...if my problem gets solved...
Best Regards
Nitin
0
 
khacharnAuthor Commented:
WolfgangKoenig
I need to know how to get the current Adobe document path...can you help me in this please...
don't mind increasing the points to a bit more...if my problem gets solved...
Best Regards
Nitin
0
 
khacharnAuthor Commented:
WolfgangKoenig
I need to know how to get the current Adobe document path...can you help me in this please...
don't mind increasing the points to a bit more...if my problem gets solved...
Best Regards
Nitin
0
 
WolfgangKoenigCommented:
There no probably no way to determine this with com/ole
But i can't create an object instance in this way:

Dim AcroDoc As Object
Set AcroDoc = CreateObject("AcroExch.Document")

This is why Acrobat Reader don't followed the Mircosoft OLE/COM product restrictions.
You can try to read out this via the api but i don't know
the SendMessage command:
SendMessage hWnd, WM_USER + ??, 0, 0

I think this is hard to solve ... perhaps you should go another way ...

WoK
0
 
khacharnAuthor Commented:
WolfgangKoenig
I need to know how to get the current Adobe document path...can you help me in this please...
don't mind increasing the points to a bit more...if my problem gets solved...
Best Regards
Nitin
0
 
WolfgangKoenigCommented:
You can look at the Adobe Homepage to determine if a
OLE typelib for Adobe Acrobat Reader exists ...

WoK
0
 
khacharnAuthor Commented:
WolfgangKoenig
I need to know how to get the current Adobe document path...can you help me in this please...
don't mind increasing the points to a bit more...if my problem gets solved...
Best Regards
Nitin
0
 
TimCotteeCommented:
khacharn, I don't think that Wolfgang has a solution for you at this point. Nor do I for that matter. The acrobat reader application doesn't seem to have the same methods available as word or excel. There may be a method using DDE but I haven't managed to get that to work yet either. Please be patient. If a solution can be found then it will be. However I will draw your attention to the EE guidelines which state that each thread should be used for a single question. Whilst this subsequent question may appear to you to be a similar one it may well involve a completely different set of experts in a resolution as the two applications are not directly comparable. I would strongly recommend that you close this question and ask a new one related to the acrobat issue. This will take your question back to the top of the question list and will also mean that any expert opening it doesn't just look at the top few comments and decide that it is sufficiently handled and move on. In this case they would never get to the bottom here where you are asking a new question.
0
 
khacharnAuthor Commented:
Soory wolf i hope you don't mind ..
but it was timcottee's solution which helped me so the points go to him...
i wish i could give you some points is that possible cottee ??
if yes could you please give wolf 50 points from the 150 i am giving you
best regards
khacharn

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 11
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now