[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1034
  • Last Modified:

excel vba max chars in string

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
OTNAdmin
Asked:
OTNAdmin
1 Solution
 
Patrick MatthewsCommented:
A String variable can hold a huge number of characters.  Perhaps it would be helpful if you posted all of your code.
0
 
CluskittCommented:
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
 
madhubabusCommented:
Please check this link for more details
http://www.vbforums.com/showthread.php?t=395267
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
byundtCommented:
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
 
byundtCommented:
Even Excel 2010 doesn't allow HYPERLINK function to accept more than 255 characters.
0
 
OTNAdminAuthor Commented:
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
 
NorieCommented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now