Results 1 to 8 of 8

Thread: [RESOLVED] Follow Hyperlink Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    272

    Resolved [RESOLVED] Follow Hyperlink Help

    I am running the below code which will open a folder based upon what the user enters into a text box.
    Code:
        varProgram = UserForm1.Text
        
         Set wordapp = CreateObject("word.Application")
    
        wordapp.Documents.Open "C:\Main\" & varWord & "_New.doc"
        
        wordapp.Visible = True
        
        strFolder = "C:\Main\" & varWord & "_New\\"
        FollowHyperlink Address:=strFolder, NewWindow:=True
    This works fine if I am just going to run it once. If I try to run the code a second time, I get permission denied? Can someone help me understand why it works perfect once, but not a 2nd time? The line that is highlighted as causing the error is this one:
    Code:
        FollowHyperlink Address:=strFolder, NewWindow:=True

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Follow Hyperlink Help

    what application are you writing your code in?
    followhyperlink is not a valid function in my version of office
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    272

    Re: Follow Hyperlink Help

    I am using this code in Excel 2000.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Follow Hyperlink Help

    in excel 2000, i have no followhyperlink function, only a worksheet event of that name
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    272

    Re: Follow Hyperlink Help

    Quote Originally Posted by westconn1 View Post
    in excel 2000, i have no followhyperlink function, only a worksheet event of that name
    It's not a function that I was using. It was simple just followhyperlink and then type the address that you want to follow. There are several different forums that I have seen this example on, this is the 1st one that came up when I googled:

    http://www.vbaexpress.com/forum/arch...php/t-536.html

    Can you provide a different example of how to accomplish the same feat as I am needing?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Follow Hyperlink Help

    on checking, followhyperlink is method of a document object, so should be
    thisdocument.followhyperlink
    activedocument.followhyperlink or in your case
    wrdapp.documents(1).followhyperlink

    this is a common problem when automating applications, when objects are not fully qualified, work once but will not repeat
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    272

    Re: Follow Hyperlink Help

    I'll test that out. I am using it on an Excel Userform, and I want to open the folder that is typed into the textbox on the Userform. It opens fine, the 1st time, but errors the 2nd. I'll have to test these out, and see if using any of the other ones will remove the issue.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Follow Hyperlink Help

    as you are doing your code in excel, you can use the followhyperlink method of any workbook object, rather than the wrdapp document object, i doubt it will make any difference
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width