rdoulaghsingh
Board Regular
- Joined
- Feb 14, 2021
- Messages
- 105
- Office Version
- 365
- Platform
- Windows
I am trying to export the notes from a single textbox on a worksheet called "CONTENTS" to a text file. The code works well, but if I click "cancel" on the saveasdialog box, then it creates a text file in the location with the name "False". I'm assuming I need a statement to handle if cancel is clicked, but nothing I've done is working so far. Any help would be appreciated. Thanks!
VBA Code:
Sub ExportMyNotes()
Dim TNotes As String
Dim WBname As String
On Error Resume Next
Application.ScreenUpdating = False
Dim FN As String
Dim FF As Integer
WBname = Replace(ActiveWorkbook.Name, ".xlsm", "")
TNotes = Worksheets("CONTENTS").TextBoxes("Notes").Text
If Worksheets("CONTENTS").TextBoxes("Notes").Text <> "" Then
FN = Application.GetSaveAsFilename(WBname & " - Project Notes.txt", _
"Text Files (*.txt), *.txt", , "Export File")
FF = FreeFile
Open FN For Output As #FF
Print #FF, TNotes
Close #FF
'End If
Else
Exit Sub
End If
Application.ScreenUpdating = True
End Sub