Case Specific error 14 out of string space

mesp9942

New Member
Joined
May 20, 2013
Messages
5
I have written a sub to read a text file as a string, edit it, and then write it back to the text file. The problem is assigning the edited text back to the string to write it to the file-it says the string is too long. How can I break up my code so that I can put all of the edited string back into the text file?
I am a novice in VBA and so I need help with the way I've written my code specifically. It can write the stream to the string textline initially, but when assigning it after the editing, there is an issue for example this line
"textline = left(textline, pOne - 1) & "{{image0" & count & "}}.jpg" & Right(textline, pTwo + 1)"

Here is what I have:

Sub elizabethwhite()
Set fso = CreateObject("scripting.filesystemobject")
filename = "C:/Users/Meghan.Sposato/desktop/tester3.htm"
Set fileobj = fso.opentextfile(filename, 1)
textline = ""
Do Until fileobj.atendofstream
textline = textline & fileobj.readall
Loop

count = 0
pOne = 1
Do
If pOne = 0 Then
Exit Do
End If

count = count + 1
pOne = InStr(pOne, textline, "<img")
pTwo = InStr(pOne, textline, ">")

If count < 10 Then
textline = left(textline, pOne - 1) & "{{image00" & count & ".jpg}}" & Right(textline, pTwo + 1)
End If
If 9 < count Then
textline = left(textline, pOne - 1) & "{{image0" & count & "}}.jpg" & Right(textline, pTwo + 1)
End If

Loop
fileobj.write textline
fileobj.Close
End Sub

Thanks,
Meghan</img")
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
What is this meant to be:

Code:
pOne = InStr(pOne, textline, " pTwo = InStr(pOne, textline, ">")

I don't see how that could compile or run
 
Upvote 0
Meghan

Where exactly do you get the error?
 
Upvote 0
It doesn't look like you advance pOne in the loop - you either need to use pOne + 1 at the start of the instr function, or increment it manually after each usage
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top