Replace string in first line of image (opened as text file)

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Replace string in first line of image (opened as text file)

Post by YasserKhalil »

Hello everyone
I am trying to replace specific text in the first line of an image (I manually opened the image using notepad++ and modify that text)
Using the following code raises an error (input past end of file)

Code: Select all

Sub Test()
    Dim sPath As String, sCont As String, f As Integer
    sPath = Environ("USERPROFILE") & "\Desktop\Sample.jpg"
    f = FreeFile
    Open sPath For Input As f
    sCont = Input(LOF(f), f)
    Close f
    sCont = Replace(sCont, "ICC_PROFILE", "ICC_PROFILX")
    f = FreeFile
    Open sPath For Output As f
    Print #f, sCont
    Close f
End Sub

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Re: Replace string in first line of image (opened as text file)

Post by YasserKhalil »

I noticed I have posted in Excel not in VBA. Can you please move the topic to VBA section?

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Replace string in first line of image (opened as text file)

Post by HansV »

Done.
Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Re: Replace string in first line of image (opened as text file)

Post by YasserKhalil »

Thanks a lot. Any idea about the question?

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Replace string in first line of image (opened as text file)

Post by HansV »

Sorry, no.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: Replace string in first line of image (opened as text file)

Post by SpeakEasy »

Open sPath For Binary As #f

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Re: Replace string in first line of image (opened as text file)

Post by YasserKhalil »

Amazing. Thank you very much.
excellent catch.