I'm wanting to export a range of cells to a text file. There's a guide how to do this on the Microsoft Website...
http://support.microsoft.com/kb/291296
It works fine, except it's a little tiring having to input the filename & path each time. I'd rather have a cell on the active worksheet (that I wish to export from) setup with a filename...& use that cell value rather than have the input box popup.
I've tried a few permutations, but can't get it to work!
How can I modify the MS code (below), to rid me of the input box & just use file name taken from the contents of a nominated cell - for example if cell b:27 has the filename C:\1.TXT in it, the macro will then export the cells with that name.
(I've only extracted the bits from their code that appoly to opening & creating the filename)
' Dimension all variables.
Dim DestFile As String
Dim FileNum As Integer
Dim ColumnCount As Integer
Dim RowCount As Integer
' Prompt user for destination file name.
DestFile = InputBox("Enter the destination filename" _
& Chr(10) & "(with complete path):", "Quote-Comma Exporter")
' Obtain next free file handle number.
FileNum = FreeFile()
' Turn error checking off.
On Error Resume Next
' Attempt to open destination file for output.
Open DestFile For Output As #FileNum
' If an error occurs report it and end.
If Err <> 0 Then
MsgBox "Cannot open filename " & DestFile
End
End If
Bookmarks