tony.reynolds
Board Regular
- Joined
- Jul 8, 2010
- Messages
- 97
I have a form that the user browses to a workbook and imports all data from columns and then once the workbook that was opend is finished with it closes.
however if the user closes the userform with the red X id like the workbook that was opened to close.
I want to exclude the workbook that we are importing to from closing and make sure we only close the import one.
Hence i have the string of the pathname and workbook.name in the TextBoxImportDirectory textbox. ("C/Users/TonyXX/Documents/ImportFile.xlsx")
I am trying to remove all the characters before the file name string and also the extension of the file (all after the "." from the string "C/Users/TonyXX/Documents/ImportFile.xlsx"
Can someone help me with code to remove these characters from the sting.
I have placed the code in the userform_Queryclose Event
the above Code removes the extension but not all before the file name i.e. "C/Users/TonyXX/Documents/" and also if it was not identical extension it wont remove it.
there are probably other ways to do it but any ideas a welcome.
however if the user closes the userform with the red X id like the workbook that was opened to close.
I want to exclude the workbook that we are importing to from closing and make sure we only close the import one.
Hence i have the string of the pathname and workbook.name in the TextBoxImportDirectory textbox. ("C/Users/TonyXX/Documents/ImportFile.xlsx")
I am trying to remove all the characters before the file name string and also the extension of the file (all after the "." from the string "C/Users/TonyXX/Documents/ImportFile.xlsx"
Can someone help me with code to remove these characters from the sting.
I have placed the code in the userform_Queryclose Event
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Dim WorkbookToCloseString
WorkbookToCloseString = Replace(TextBoxActiveFileName, ".xlsx", "")
Workbooks(WorkbookToClose).Close SaveChanges:=False
End Sub
the above Code removes the extension but not all before the file name i.e. "C/Users/TonyXX/Documents/" and also if it was not identical extension it wont remove it.
there are probably other ways to do it but any ideas a welcome.