Solved

excel vba max chars in string

Posted on 2010-09-23
7
1,029 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
Industry Leaders: 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!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete row if does not start with 0 43 38
need 2017 datas one by one using macro 12 38
I NEED KEEP THE CONDITIONAL  FORMATTING 24 28
Overwriting Named Ranges 13 31
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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 Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

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