![access vba code examples okay cancel access vba code examples okay cancel](https://cdn.wallstreetmojo.com/wp-content/uploads/2019/09/VBA-Examples-1.png)
Since that is a variable that contains the location of the file, its not a string and could be the cause of your problems. Note, I have removed the quotes from selectedfile. Here is sample code to open an Excel workbook so it can be worked on in code: If you want to do this all programmatically then you need to detail what error message you are getting. If you just need to open the file to do the work, then you can do it simply: Do you need to do this programmatically or do you need to look at the file to see what needs to be done? You said you need to open the file, delete some rows, check some headers and save. Hi John, I'm an independent adviser and will try to help. Supposing to invoke it by a command button called cmdOpen placed into a form. If FileExists(Me.fullPathPDFfile) Then openFileName Me.fullPathPDFfile 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.
![access vba code examples okay cancel access vba code examples okay cancel](https://cdn.wallstreetmojo.com/wp-content/uploads/2019/10/VBA-Project-Password-Example-1-4.png)
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.