Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-07-20
22
Medium Priority
?
367 Views
Last Modified: 2007-12-19
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
Comment
Question by:khacharn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
  • 3
  • +1
22 Comments
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6301600
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
 
LVL 43

Expert Comment

by:TimCottee
ID: 6301601
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
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6301609
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!

 

Expert Comment

by:nvivas
ID: 6301650
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
 

Author Comment

by:khacharn
ID: 6301675
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
 

Author Comment

by:khacharn
ID: 6301701
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
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6301761
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
 

Author Comment

by:khacharn
ID: 6301764
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
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6301765
You can also use the "View" menu in the VBE to open the object catalog ...
0
 

Author Comment

by:khacharn
ID: 6301768
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
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6301796
You can also use the "View" menu in the VBE to open the object catalog ...
0
 

Author Comment

by:khacharn
ID: 6301824
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
 

Author Comment

by:khacharn
ID: 6301832
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
 

Author Comment

by:khacharn
ID: 6301927
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
 

Author Comment

by:khacharn
ID: 6302036
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
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6302196
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
 

Author Comment

by:khacharn
ID: 6302198
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
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6302209
You can look at the Adobe Homepage to determine if a
OLE typelib for Adobe Acrobat Reader exists ...

WoK
0
 

Author Comment

by:khacharn
ID: 6302225
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
 
LVL 43

Accepted Solution

by:
TimCottee earned 450 total points
ID: 6302338
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
 

Author Comment

by:khacharn
ID: 6303212
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
 
LVL 43

Expert Comment

by:TimCottee
ID: 6307456
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question