Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Application path 1

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
Guys,

I have a macro that i embedded on the MS word application. All the supporting files for the macro are pushed into c:/documents and settings/dng/.../startup on all users machines in the company...

so now when i (as a user) open MS word and open a doc file that is on my c drive and try to run the macro...WHAT SHOULD BE THE APPLICATION PATH THAT I SHOULD PUT IN THE CODE SO THAT IT REFERS TO THE c:/...../startup folder because my supporting files are there...

i tried

1.App.path("mypathhere")
2. Application.Startuppath("mypathhere")

and i tried lot of other variations...but nothing worked...

any suggestions...

-DNG
 
Hi DNG,

This rather depends on

(a) What you mean by supporting files, and
(a) (perhaps)where the macro actually is

There isn't any real concept of supporting files in Word. If you are talking about macros/procedures in a global template then you should be able to run them but, depending on how you do it, you may need to set a reference. If you are talking about actual files, it rather depends what they are.

Can you give some more details?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

Thanks for your input...sorry for not being more informative on my question...

I have a macro written in VBA...this macro is attached to all the MS word applications on all users machines...i mean when a user opens the ms word, there is button to invoke this macro and run it...

now what i have done is, i have put the mymacro.dot file in the c:/documents and settings/dng/.../startup folder on all the users machines...

and i have to set my app.path to point to this folder...

-DNG
 
Hi DNG,

I don't know what you mean by app path.

If you have your code in a global template (a .dot file in the startup directory) and the button is available in (your users') Word, what is it that isn't working?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
oops...sorry again...reliazed that i forgot to mention the important piece of information...

here you go...

in my macro i use XML file to load the contents of it into an array and use it...so in order to load the XML file i have this line of code in my macro...

Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
        If FSO.FileExists([red]Application.StartupPath[/red] & "\Xml\Mapping.XML") Then
    xmlmapfile = FSO.GetFile([red]Application.StartupPath[/red]& "\Xml\Mapping.XML").OpenAsTextStream(ForReading).ReadAll
    Else

ok now as i said earlier...i have all the supporting files in the c:/..../startup location..i have also put this Mapping.XML file there...

but as i said Application.Startuppath is not working to load the XML file...

-DNG
 
Hi DNG,

It works for me - just as posted (apart from needing a space before an ampersand) when I create the referenced file.

Are you quite sure (a) that you are using the location under Tools > Options > File Locations > Startup and (b) you have a file called mapping.xml in a sub-directory called xml?

I'm sorry if the questions seem elementary but, as I say, it looks correct and works for me.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

I have everything set correctly...

i think it is the problem with references...here is the part of the function that i use...

Public Function GetMappedName() As String
[red] Dim oXML As MSXML2.DOMDocument[/red]
Dim oRoot As IXMLDOMNodeList
Dim oRow As IXMLDOMNode

it errors on the first line itself...i dont know why...i have referenced

Microsoft XML, V3.0 in the project module...i think this reference is not copying to the .dot file...how do i make sure that .dot file has this reference...

Thanks

-DNG
 
Hi DNG,

I've just realised what I think you're saying. I think you probably have a missing reference.
[ul][li]Open your Addin (go to ...\word\startup, right click on it and select Open).[/li]
[li]Open the VBE, select the Addin in the Project Explorer[/li]
[li]Go To Tools > References (in the VBE). Are any references marked as MISSING?[/li][/ul]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
No luck yet...can you go thru the code and see where am i going wrong...

i tried putting messages boxes at various places and currently i get the error on RED line

Code:
Public Function GetMappedName() As Deltek
'    Dim oXML As MSXML2.DOMDocument
'    Dim oRoot As IXMLDOMNodeList
'    Dim oRow As IXMLDOMNode
'    Dim FSO As Scripting.FileSystemObject
    Dim oXML As Object
    Dim oRoot As Object
    Dim oRow As Object
    Dim FSO As Object
    Dim oFile As Object
    Dim oTextStream As Object


    Set oXML = CreateObject("MSXML2.DOMDocument")
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oFile = CreateObject("Scripting.FileSystemObject")
    Set oTextStream = CreateObject("Scripting.FileSystemObject")
    
    
'    Set oRoot = CreateObject("IXMLDOMNodeList")
'If False Then
'    Set oRow = CreateObject("IXMLDOMNode")


    Dim xmlmapfile As String
    Dim Result As dng
    Dim i As Long
    Dim sFilePath As String
   
    MsgBox "Test - Inside getMappedName1"
    sFilePath = Application.StartupPath & "\Xml\Mapping.XML"
    MsgBox sFilePath
    
        If FSO.FileExists(sFilePath) Then
        MsgBox "FileExists"
        Set oFile = FSO.GetFile(sFilePath)
        MsgBox "After oFile"
[red]        Set oTextStream = FSO.OpenTextFile(oFile, ForReading, True) [/red]
'   .OpenAsTextStream(ForReading).ReadAll
        MsgBox "After oTextStream"
        xmlmapfile = oTextStream
    Else
        MsgBox "File not Exists"
        GetMappedName = Result
    Exit Function
    End If
    
    MsgBox "Test - Inside getMappedName2"
    
    'Set oXML = CreateObject("MSXML2.DOMDocument")
    Call oXML.loadXML(xmlmapfile)
    
    MsgBox "Test - Inside getMappedName3"
    
    Set oRoot = oXML.getElementsByTagname("Row")
    Result.RowCount = oRoot.Length
    If oRoot.Length > 0 Then
    i = 0
    ReDim Result.mapping(oRoot.Length - 1)
    
    MsgBox "Test - Inside getMappedName4"
    
    For Each oRow In oRoot
    With Result.mapping(i)
        .Code = oRow.SelectNodes("Code").Item(0).Text
        .Name = oRow.SelectNodes("Name").Item(0).Text
        .MapName = oRow.SelectNodes("MapName").Item(0).Text
        
    End With
    i = i + 1
    Next
    End If
    Set oXML = Nothing
    GetMappedName = Result
End Function

-DNG
 

If you are missing references (by accident or design) then "ForReading" may not be defined - try using 1 (one) instead.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Thanks Tony..its working now after making couple more changes...

thanks for being patient...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top