Consulting

Results 1 to 5 of 5

Thread: Solved: Assign Variables On Open

  1. #1
    VBAX Regular
    Joined
    Apr 2005
    Posts
    27
    Location

    Solved: Assign Variables On Open

    I am opening a document through a com interface that adds a bookmark containing a delimited string, i.e sarah|girl|texas (where | is the delimiter)

    What I would like to do on open is to separate the elements and store them as public variables so they can be used by other macros, i.e

    [VBA] Sub Name()
    Selection.TypeText Text:=Name
    End Sub[/VBA]

    would produce Sarah when Name() is called.

    It is the document_open macro that I cant get to work -

    [VBA] Sub Document_Open()
    Name = Split(Bookmarks("BookMarkName").Range.Text, "|")(0)
    Gender = Split(Bookmarks("BookMarkName").Range.Text, "|")(1)
    ' etc
    End Sub
    [/VBA]
    Should assign values to Public Name As String (etc)

    But this does not work. When Name() is called nothing happens. No error msg either.

    The document_open should conclude with the deletion of the bookmark, but I have yet to get that far.

    Can anybody help? If I have gone about a completely inefficient way I would be happy to change tact entirely.

    Thank you in advance.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Levski,
    Welcome to VBAX

    I'm guessing that Document_Open may be running before the Bookmark is created. Can you test for that with a message box?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Apr 2005
    Posts
    27
    Location
    Thank you for the prompt reply.

    The msgbox opens first, suggesting I am trying to dissect a string that does not exist at that point.

    Any ideas how I can ensure that the macro runs automatically after the bookmark has been created? I do not know much about Word at all Im afraid, just creating a word link for an app in done in delphi.
    Last edited by Levski; 04-03-2005 at 08:43 AM. Reason: Updated

  4. #4
    VBAX Regular
    Joined
    Apr 2005
    Posts
    27
    Location

    Thumbs up

    Managed to get the variables straight through the interface without having to use the bookmark.

    Thanks all the same. I will probably be back

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Levski: Sounds like it's solved. If so, could you click the Thread Tools dropdown (top of page) and choose Mark Solved?

    Thanks! And welcome to VBAX.
    ~Anne Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •