Editing Notepad file from VBA

mserfling

New Member
Joined
Nov 6, 2020
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
Hello, I am trying to edit a open notepad file from VBA. What I need to happen is deleting certain strings of text. "QTY. 1 EACH SIZE: .75 X 1.375" & "Multiline Text" & "Singleline Text" <-- If any of these shows up in the text file I need it gone and replaced with nothing. Any help will be appreciated.






VBA Code:
Private Sub CreateText_Click()
    Dim myCell
    Dim i As Integer
    Dim Str As String
    Dim LastRow As Variant
    Dim JobNum As String
    Dim ClearTxt As String
    
    On Error Resume Next
    
        JobNum = Right([B3], 6) '<----------------------------------- Selects just the number for the job
        MkDir "C:\Trotec\Laser Jobs\JobNumbers\" & JobNum '<--------- Creates a folder named with the job number

        
        
        
    Range("A1:A150").Select '<--------------------------------------- Specified cells with blanks will be deleted
    Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete '<----- Deletes rows with condition
    'MichaelSerfling





    LastRow = Cells(Rows.Count, "A").End(xlUp).Row '<---------------- Sweeps through until Str is seen
    ClearTxt = "QTY. 1 EACH SIZE: .75 X 1.375" & "Multiline Text"
    Str = "QTY. 1 EACH SIZE: .75 X 1.375" '<------------------------- Specify term

    For i = 1 To LastRow Step 1 '<-----------------------------------
       If Sheet1.Range("A" & i).Value = Str Then '<------------------ Looks for the phrase set above
          Sheet1.Range("A" & i + 7).Resize(LastRow, 4).Copy '<------- Offsets by 7 to avoid certain rows
          Shell "notepad.exe", vbNormalFocus '<---------------------- Opens Notepad
          SendKeys "^V" '<------------------------------------------- Paste the range
          
          Exit Sub
       End If
    Next i

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Is the use of notepad strictly required? If not it might be worth to consider, to load the contents of your file directly into memory, do some parsing / replacing and write the resulting content back to disk.
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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