Solved

excel vba max chars in string

Posted on 2010-09-23
7
1,025 Views
Last Modified: 2012-06-27
I have composes an excel function called StaticMap which appends text to it and it should return more than 255 chars, but when I run it it always stop at around 252.

The call is wrapped around inside a hyperlink function like this:
=HYPERLINK(StaticMap(a1:g1 | "link")

Public Function StaticMap(data as String) As String
...some parsing...
StaticMap = "http://maps.google.com/maps/api/staticmap?size=512x512&maptype=roadmap"
StaticMap = StaticMap & "&markers=color:blue|label:A|" & a
StaticMap = StaticMap & "&markers=color:green|label:B|" & b
StaticMap = StaticMap & "&markers=color:red|label:C|" & c
StaticMap = StaticMap & "&sensor=false"

End Function

While tracing the StaticMap variable it stops at 252 chars.
Is this a limitation of VBA or Excel?
How to allocate more memory to a string object?
0
Comment
Question by:OTNAdmin
7 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33745719
A String variable can hold a huge number of characters.  Perhaps it would be helpful if you posted all of your code.
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 33745813
A String var, in theory, can hold up something between 2^16 and 2^32 as its maximum. You really should post the code, cause your problem has another cause.
0
 
LVL 3

Expert Comment

by:madhubabus
ID: 33745867
Please check this link for more details
http://www.vbforums.com/showthread.php?t=395267
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 80

Expert Comment

by:byundt
ID: 33746554
The problem is with the HYPERLINK function not your user-defined function. HYPERLINK (in my test with Excel 2003) cannot receive a 320 character test string, but does work with a 70 character one.

To prove this, put the following formula in a worksheet cell:
=LEN(StaticMap("link"))                 You should be able to return well over 255 characters to the LEN function
0
 
LVL 80

Expert Comment

by:byundt
ID: 33746706
Even Excel 2010 doesn't allow HYPERLINK function to accept more than 255 characters.
0
 

Author Comment

by:OTNAdmin
ID: 33747697
I think you are right =HYPERLINK function in excel has a huge limitation.
I am trying to generate a large URL >260 chars, but its always cut off.

Here is another forum discussing this issue:
http://www.mrexcel.com/forum/showthread.php?t=47346

I am using Excel 2010. I can't believe that has been an outstanding issue since 1997.
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 33758055
Is it only the URL you want to generate?
How about actually doing that using the Hyperlinks collection?
What you have now is a UDF to create the actual URL and a worksheet function, HYPERLINK , to actually create the link.
You can add a hyperlink to a worksheet with something like this.

Option Explicit



Sub test()

Dim rng As Range



    Set rng = Worksheets(1).Range("A1")



    rng.Hyperlinks.Add rng, StaticMap(rng), , , "Static Map"



End Sub



Public Function StaticMap(data As Range) As String



    StaticMap = "http://maps.google.com/maps/api/staticmap?size=512x512&maptype=roadmap"

    StaticMap = StaticMap & "&markers=color:blue|label:A|"

    StaticMap = StaticMap & "&markers=color:green|label:B|"

    StaticMap = StaticMap & "&markers=color:red|label:C|"

    StaticMap = StaticMap & "&sensor=false"





End Function

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now