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")
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: