Posts by peterhw

    Hope the file uploaded OK.
    I just do not understand why this Simple Code fails at the first hurdle
    So basic I am sure but like to understand why this fails - i.e. not just the solution


    [ATTACH=CONFIG]56563[/ATTACH]


    Code
    Private Sub CommandButton1_Click()
        Set myOlApp = CreateObject("Outlook.Application")
        Set myNameSpace = myOlApp.GetNameSpace("MAPI")
        Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)   '   <<<<<<<<<<<<Fails here with INVALID PROCEEDURE CALL OR ARGUMENT
        Set myNewFolder = myFolder.Folders("IMS")
        'The following Visual Basic for Applications example returns the first folder.
        Set myNewFolder = myFolder.Folders(1)
    End Sub

    I have the following code (bits copied from anywhere!) which seems to work................ BUT....



    • why is "Const olContactItem = 2" used
    • how do I add Notes ? '.Notes = "what a load of rubbish" doesn't work and I just can't find the correct field
    • how do I save to an alternative folder (in this case 'IMS')



    Appreciate any help


    Re: Accessing word macros from excel


    Quote from sleeper108;606362

    I am getting a



    Dim my_replacements(2, 2)
    [/code]
    .


    the above only defines the following cells. You need to replace with Dim my_replacements(2, 9) - this should eliminate the subscript error


    [TABLE="width: 56"]

    [tr]


    [td]

    my_replacements(0,0)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(0,1)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(0,2)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(1,0)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(1,1)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(1,2)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(2,0)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(2,1)

    [/td]


    [/tr]


    [tr]


    [td]

    my_replacements(2,2)

    [/td]


    [/tr]


    [/TABLE]

    Re: Accessing word macros from excel


    sorry if I had been at cross purposes. I had gone to what I thought was the bottom of the thread but was in fact only the end of page 1. Now found page 2 .


    Many thanks for all your support.


    PS - just edited to ADD I have now run the code and it works - many , many thanks

    Re: Accessing word macros from excel


    Thought I had made a reply but can't locate.


    Now made alterations and the following appears to work correctly except that the replacements are not made.
    WORD opens
    WORD saves to file ProblemsA
    WORD quits
    ...but no replacements have been made (I changed to "and" for multiple replacements)



    Re: Accessing word macros from excel


    realised I had not correctly got 'wrdApp' in all correct places.
    The code below seems to achieve everything ** except ** make the replacements. WORD opens (visible).
    A file is saved i.e. ProblemsA.docx but it appears to be the same as the original - i.e. no replacements have taken place.




    Re: Accessing word macros from excel


    Quote from cytop;604652

    The file is already open... shows the reason why error handlers should be included in code.


    Either:
    Close any copies of the file you have open.
    Or
    Use TaskManager to check for running but hidden copies of Word and kill the processes or restart your machine.


    Guess I am a little out of my depth and where to look.


    I killed the process using TASKMANAGER then tried to run and failed trying to SAVE, QUIT etc stating there was no object.
    Presumably there are some handlers in word for checking if the file or object is closed / open == I just don't seem to be thinking along the right path


    Re: Accessing word macros from excel


    I seem to be struggling and your help is valued.


    I had the basics of your example but my system seems to 'lock' then comes up with FILE is locked for editing, read only etc.


    Doesn't seem to close. Needs an object.



    Re: Accessing word macros from excel


    Just trying to implement something for myself and wondering how I could for example replace


    my_replacements(1,1) with my_replacements(1,2) where my_replacements(1,1)= "replacement_1" and my_replacements(1,2) is the new text for this occurrence e.g. name
    my_replacements(2,1) with my_replacements(2,2) where my_replacements(2,1)= "replacement_2" and my_replacements(1,2) is the new text for this occurrence e.g. address_line_1
    my_replacements(3,1) with my_replacements(3,2) where my_replacements(3,1)= "replacement_3" and my_replacements(1,2) is the new text for this occurrence e.g. city
    etc.

    I have written several macros in VBA / EXCEL but want to access a WORD (template / master) then replace various fields from my VBA EXCEL application database.
    Example replace my_address_line1 (in the word document, with the actual address line from my text database accessed from VBA / Excel


    Just not sure if I can do what I want to achieve!


    When the WORD document is 'edited' then I wish to save and either Print or Email. I don't want to save macros into the final word document id sending by email (I guess that would be poor practice).


    There doesn't seem to be an option to save a file in word which is macro enabled or disabled.


    Just trying to get some pointers before I head off in the complete wrong direction!

    I tried to use the sumproduct function and struggled (with some ideas from this and other forums).


    Eventually I got the following code to provide an answer to how many occurences of Apple in column A AND # 1 in column B


    =SUMPRODUCT(--(A1:A4="Apple"),--(B1:B4=1))


    could someone please advise the significance of the -- (double - minus) before each of the specified ranges. [I came across this by luck and it worked]