Getopenfilename Default File Path Windows

Posted on by  admin

Campbell biology 9th edition chapter 7 summary of the outsiders. Context: My goal is to update links between PPT and Excel, and have the user select the new file to link to. We have monthly files with just the numbers changing (eg, table sizes are all fixed).I'm trying to set the default directory that Excel shows when using the GetOpenFilename. The trick is my code is in PowerPoint, and I am opening the Excel file with the CreateObject('Excel.Applic ation'). The code I tried is here, but when it opens the GetOpenFilename, it goes only to MyDocuments:Set exl = CreateObject('Excel.Applic ation')ChDrive Left(ActivePresentation.Pa th, 2)strNewDrive = Left(ActivePresentation.Pa th, 2)ChDir ActivePresentation.PathstrNewDir = ActivePresentation.PathExcelFileNew = exl.Application.GetOpenFil ename(, 'Select Excel File')' The rest of the code is a bit clumsy, but attached. I use GetSetting and SaveSetting to store MRU paths for this purpose. That way you can access the paths from any Office app hosting VBA.

File Path Example

Windows

Default Path Windows 10

If you just need to select an Excel File maybe this would work in PPT (The code does not seem to be attached BTW)Dim exl As ObjectDim fd As FileDialogDim strFilename As StringSet exl = CreateObject('Excel.Applic ation')Set fd = PowerPoint.Application.Fil eDialog(ms oFileDialo gOpen)With fd.AllowMultiSelect = False.Filters.Clear.Filters.Add 'Excel Files', '.xls,.xlsx'.InitialFileName = 'C:UsersOptiplexDesktop 'If.Show = True ThenstrFilename =.SelectedItems(1)End IfEnd WithMsgBox 'Path= ' & strFilenameMsgBox 'Filename= ' & Right(strFilename, Len(strFilename) - InStrRev(strFilename, ')).

Comments are closed.