Solved

excel vba max chars in string

Posted on 2010-09-23
7
1,030 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 34

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

726 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