Solved

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

Posted on 2001-07-20
22
351 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
  • 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 150 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now