Solved

excel vba max chars in string

Posted on 2010-09-23
7
1,026 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 81

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 81

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delete texts with font color 16 30
Boolean help 6 27
Vlookup nonexact IP address match 32 48
Excel 2016: auto-number column of merged cells. 47 23
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…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

920 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

14 Experts available now in Live!

Get 1:1 Help Now