opening a text file and keeping it active/open

hearthhrob4gals

Board Regular
Joined
Aug 20, 2014
Messages
142
Hi,

I want to create a text file. copy data from excel into it and display the text file...the below code creates a text file and pastes the data from excel. However, i cant see the text file open. i want the text file to be the active window. any help on this would be appreciated.

VBA Code:
Sub TextFile_Create()

Dim TextFile As Integer
Dim FilePath As String

  FilePath = ActiveWorkbook.Path & "\AuditLog10.txt"
  TextFile = FreeFile

  Open FilePath For Output As TextFile
  Print #TextFile, Sheets("Input").Range("dd1").Value

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

diddi

Well-known Member
Joined
May 20, 2004
Messages
3,299
Office Version
  1. 2010
Platform
  1. Windows
i suggest you just use a userform with a copy of the text file as a preview. you would have to Shell to Notepad or similar to view the file and then you have issues of having to bring the focus back to excel, and also possible problems with writing to the file while it is in use by another application
 

Watch MrExcel Video

Forum statistics

Threads
1,129,795
Messages
5,638,366
Members
417,023
Latest member
Zimbo38

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
Top