VBA text box question

jdotbonk

New Member
Joined
Feb 26, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello All!

I was curious if anyone is familiar with how I can create a “Generate Text File” button/command to this sheet that would spit out this example text file below.

The only piece of data that would change each day is the amount to match the yellow highlighted cell in the spreadsheet, & the date to today’s current date. Any advice is appreciated!
Cheers!
 

Attachments

  • F5317DBF-1835-4374-A319-86F37D53BE6D.jpeg
    F5317DBF-1835-4374-A319-86F37D53BE6D.jpeg
    97.4 KB · Views: 8

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe this snippet?
VBA Code:
Dim TxtFile As String
Dim Msg0 As String, fFile As Long, MSG
'
TxtFile = "C:\PROVA\myTXTFile.Txt"                              '<<< Your output file
Msg0 = "JRB COLLATERAL, ####, @@@@,,,,The other text, hello"    '<<< Your BASE message with "placeholders"
'
fFile = FreeFile
MSG = Replace(Msg0, "####", Format(Range("D2").Value, "0.00"), , , vbTextCompare)   '<<< YOUR Range
MSG = Replace(MSG, "@@@@", Format(Date, "yyyy-mm-dd"), , , vbTextCompare)
'
'Create txt file:
Open TxtFile For Output As #fFile
    Print #fFile, MSG
Close #fFile
The lines marked <<< need to be customized
 
Upvote 0
Maybe this snippet?
VBA Code:
Dim TxtFile As String
Dim Msg0 As String, fFile As Long, MSG
'
TxtFile = "C:\PROVA\myTXTFile.Txt"                              '<<< Your output file
Msg0 = "JRB COLLATERAL, ####, @@@@,,,,The other text, hello"    '<<< Your BASE message with "placeholders"
'
fFile = FreeFile
MSG = Replace(Msg0, "####", Format(Range("D2").Value, "0.00"), , , vbTextCompare)   '<<< YOUR Range
MSG = Replace(MSG, "@@@@", Format(Date, "yyyy-mm-dd"), , , vbTextCompare)
'
'Create txt file:
Open TxtFile For Output As #fFile
    Print #fFile, MSG
Close #fFile
The lines marked <<< need to be customized
Hi Anthony - appreciate your feedback! I think I should have started out with step 1, which is getting a “Generate Text File” button similar to the already present “Generate Email” button on the worksheet. I think then I would be able to modify what the text file spits out after being able to display it.

Thanks!
 
Upvote 0
Are you asking to have a button that appears and disappears?
If Yes, then add a commandbutton to your sheet, taking it from the ActiveX controls: Menu /Develop /Insert; select CommandButton from the ActiveX list of controls; draw the commandbutton.

If you want to hide it, execute the instruction Sheets("sheet3").CommandButton1.Visible = False (for example within a Sub Workbook_Open)
When you need the button be visble, execute the instruction Sheets("sheet3").CommandButton1.Visible = True
Adapt sheet name and commandbutton name to your situation
 
Upvote 0

Forum statistics

Threads
1,215,601
Messages
6,125,758
Members
449,259
Latest member
rehanahmadawan

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