The following code instead to open and work with your excel file : Public Function FileExists(strPathFile As String) As BooleanįileExists = ((GetAttr(strPathFile) And vbDirectory) = 0) Public Sub openFileName(ByVal strFullPath As String)ĬreateObject("Shell.Application").Namespace(0).ParseName(strFullPath).InvokeVerb "Open" Public Function cmdFileDialog() As String Private Const strPathPDF As String = "C\placeYourPathHere\" ' to be customized. I think no need to use automation to achieve your task, try replace your code by this solution. Set objXL = GetObject(, selectedFile, "Excel.Application") I tried adding the following code but it errors out: If Right(selectedFile, 5) ".xlsx" Then MsgBox "Invalid file type! Expecting. If Dir(selectedFile) = "" Then MsgBox "The thle path provided does not exist.": Exit Sub If selectedFile = "" Or IsNull(selctedFile) Then Exit Sub I need the first part because the file name will change from month to month but once I've selected the file I need to be able to open the file,ĭelete some rows from the beginning, check the headers, save as. I have written code to select an Excel file when prompted but I now need to continue the code to open that file.
0 Comments
Leave a Reply. |