MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old May 16th, 2006, 07:44 PM   #7
Von Pookie
MrExcel MVP, Administrator
 
Von Pookie's Avatar
 
Join Date: Feb 2002
Location: The act or process of locating.
Posts: 13,283
Default

...or, I could just have never noticed that before. I'm not really sure at the moment.

Either way: you can edit the code to check. If the name has spaces in it, have the link entered with the quotes, otherwise without.


Code:
    'check if the text contains a space
    If InStr(1, VariableSheetName, " ") > 0 Then
        'if text contains a space, add link with single quotes
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        "'" & VariableSheetName & "'!A1", TextToDisplay:=VariableSheetName
    Else
        'if text does not contain a space, add link without quotes
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        VariableSheetName & "!A1", TextToDisplay:=VariableSheetName
    End If
Edit: Alternately, you could just not allow spaces in the names. If there are any entered, change them to an underscore, for example:

Code:
VariableSheetName = InputBox("Site Name", "Enter new Site name", "")

If InStr(1, VariableSheetName, " ") > 0 Then VariableSheetName = Replace(VariableSheetName, " ", "_")
Then you won't have to worry about the quotes for those links.
Von Pookie is offline   Reply With Quote
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 07:44 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.