Results 1 to 11 of 11
  1. #1
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    I have a word2007 Userform that I would like to apply a command button, that would open Google Map at Desired location. I know I can use this code to open Google Map.

    Code:
    ActiveDocument.FollowHyperlink "http://maps.google.com?q
    Since Iím using a word document how do I attach an address, do I use a Formfield that I have named or ?
    The address info is on the main opening document called "Client Info"

    Code:
    Dim strAddress As String
    strAddress = Range("") & ", " & Range("")
    ' Replace spaces with +
    strAddress = Replace(strAddress, " ", "+")
    ActiveDocument.FollowHyperlink "http://maps.google.com?q=" & strAddress

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='ababenchrist' post='791669' date='01-Sep-2009 08:16']Since Iím using a word document how do I attach an address, do I use a Formfield that I have named or ?[/quote]
    If you are creating a document from scratch, you could use form fields, but the print display may not be what you want. You might have better results using a bookmark, a custom style (e.g., MyAddressBlock), or a selection. Word also seems to have an uncanny ability to identify an address itself, which kicks in when you go to print an envelope. I think we have had a thread about tapping into that sixth sense, but I can't recall whether the community found a way to do it.

  3. #3
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='jscher2000' post='791678' date='01-Sep-2009 09:38']If you are creating a document from scratch, you could use form fields, but the print display may not be what you want. You might have better results using a bookmark, a custom style (e.g., MyAddressBlock), or a selection. Word also seems to have an uncanny ability to identify an address itself, which kicks in when you go to print an envelope. I think we have had a thread about tapping into that sixth sense, but I can't recall whether the community found a way to do it.[/quote]

    Hi jscher2000
    I will be creating a document from scratch. It does not have to print, just open Google Map with data from my pre-selected address on my word2007 document named "Client Info" so that when Google Map opens it already has the distination. I can use Form Fields to enter the Pre-selected addresses thats not a problem. So if I use Form Fields how would I apply them to code.

    also I can print once there. Even thought the print idea sounds really cool.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='ababenchrist' post='791692' date='01-Sep-2009 11:08']It does not have to print, just open Google Map with data from my pre-selected address on my word2007 document named "Client Info" so that when Google Map opens it already has the distination. I can use Form Fields to enter the Pre-selected addresses thats not a problem. So if I use Form Fields how would I apply them to code.[/quote]
    In earlier versions of Word, the text fields, which Word 2007 now considers "Legacy controls," could be identified by a bookmark. To retrieve the value of the field in code, you used syntax such as this to work with the contents of the fields:
    Code:
    ActiveDocument.FormFields("Street").Result & ", " & ActiveDocument.FormFields("City").Result
    Of course, Word 2007 introduced a new set of controls which work differently. They are called ContentControls, and I haven't tried to program them yet. If you search here, you may find helpful threads. For reference, here is the MSDN page on the ContentControls collection from which you can explore related objects, methods, and properties: ContentControls Collection [Word 2007 Developer Reference].

    === Edit ===

    Actually, you might want to start your visit to MSDN with this page: Working with Content Controls [Word 2007 Developer Reference].

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    [quote name='ababenchrist' post='791669' date='01-Sep-2009 11:16']I have a word2007 Userform that I would like to apply a command button, that would open Google Map at Desired location. I know I can use this code to open Google Map.

    Code:
    ActiveDocument.FollowHyperlink "http://maps.google.com?q
    Since Iím using a word document how do I attach an address, do I use a Formfield that I have named or ?
    The address info is on the main opening document called "Client Info"

    Code:
    Dim strAddress As String
    strAddress = Range("") & ", " & Range("")
    ' Replace spaces with +
    strAddress = Replace(strAddress, " ", "+")
    ActiveDocument.FollowHyperlink "http://maps.google.com?q=" & strAddress
    [/quote]
    In terms of what to substitute for "strAddress" in the hyperlink - you can do an experiment by keying a given address into Google Maps, and seeing what kind of code it generates for the address (which you can access by clicking the link above the map to Send to someone).
    So for instance, if I do a Google Map search for "350 Hudson Street, New York, NY", the code the map generates is:
    Code:
    <http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=350+Hudson+Street,+NY,+NY&sll=37.0625,-95.677068&sspn=35.547176,79.013672&ie=UTF8&ll=40.728592,-74.007211&spn=0.008309,0.01929&z=16&iwloc=A>
    - which might provide some clues as to what you need to put in as the address in the hyperlink - for instance, if I put a hyperlink into Word with the following hyperlink address:
    Code:
    http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=350+Hudson+Street,+NY,+NY
    - then clicking the hyperlink takes me to a Google Map showing that address.

    You might be able to use a similar pattern to convert your strAddress into something you can append to the Google Maps link.

    Gary

  6. #6
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='Gary Frieder' post='791752' date='01-Sep-2009 18:37']In terms of what to substitute for "strAddress" in the hyperlink - you can do an experiment by keying a given address into Google Maps, and seeing what kind of code it generates for the address (which you can access by clicking the link above the map to Send to someone).
    So for instance, if I do a Google Map search for "350 Hudson Street, New York, NY", the code the map generates is:
    Code:
    <http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=350+Hudson+Street,+NY,+NY&sll=37.0625,-95.677068&sspn=35.547176,79.013672&ie=UTF8&ll=40.728592,-74.007211&spn=0.008309,0.01929&z=16&iwloc=A>
    - which might provide some clues as to what you need to put in as the address in the hyperlink - for instance, if I put a hyperlink into Word with the following hyperlink address:
    Code:
    http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=350+Hudson+Street,+NY,+NY
    - then clicking the hyperlink takes me to a Google Map showing that address.

    You might be able to use a similar pattern to convert your strAddress into something you can append to the Google Maps link.

    Gary[/quote]
    Thank you Those are both great ideas, I shall play around with some different address and see what happens.

  7. #7
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much this method worked fantasic
    Code:
    Dim strAddress As String
    strAddress = ActiveDocument.FormFields("Street").Result & ", " & ActiveDocument.FormFields("City").Result
    strAddress = Replace(strAddress, " ", "+")
    ActiveDocument.FollowHyperlink "http://maps.google.com?q=" & strAddress
    Just gave the bookmarks the names as mentioned
    WA-LA, PERFECTO MUNDO

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    [quote name='ababenchrist' post='791814' date='02-Sep-2009 10:35']Thank you so much this method worked fantasic[/quote]
    Great! - glad that worked.

    Gary

  9. #9
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now if I want to use this same code for bookmarks, I Know I need to replace the FormFields with Bookmark
    Code:
    Dim strAddress As String
    strAddress = ActiveDocument.FormFields("Street").Result & ", " & ActiveDocument.FormFields("City").Result
    strAddress = Replace(strAddress, " ", "+")
    ActiveDocument.FollowHyperlink "http://maps.google.com?q=" & strAddress
    and I tried using .Select or .Range instead of .Result
    Code:
    strAddress = ActiveDocument.Bookmarks("Street").Result & ", " & ActiveDocument.FormFields("City").Result

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try using .Range.Text:

    strAddress = ActiveDocument.Bookmarks("Street").Range.Text & ", " & ActiveDocument.FormFields("City").Range.Text

  11. #11
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi HansV
    Thank you Very Much
    It works great

Posting Permissions

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