Åtkomst till VBA - Öppna Excel -fil

Innehållsförteckning

Öppna Excel -fil

Denna funktion nedan öppnar en Excel -fil med Access VBA.

Innan du använder funktionen, se till att lägga till en referens till Microsoft Excel Object Library genom att gå till Verktyg> Referenser och kontrollerar Microsoft Excel Object Library.

Public Function OpenExcelFile (strFilePath As String) As Boolean 'Required: Tools> Refences: Add reference to Microsoft Excel Object Library Dim appExcel As Excel.Application Dim myWorkbook As Excel.Workbook Set appExcel = CreateObject ("Excel.Application") Set myWorkbook = appExcel.Workbooks.Open (strFilePath) appExcel.Visible = True 'Do Something or Just Leave Open Set appExcel = Nothing Set myWorkbook = Nothing End Function' Användningsexempel Sub OpenExcelFile_Example () Ring OpenExcelFile ("C: \ Users \ StevePC2 \ Downloads \ test.xlsx ") Slut Sub

Öppna Word -dokument med Access VBA

Ange först en referens till Word -biblioteket för Access VBA -miljön.

Notera: Du skulle göra detta i VBE genom att gå till Verktyg> Referenser och markera Microsoft Word 15.0 Object Library.

Följande kod låter dig öppna ditt Word -dokument med Access:

Dim WordDoc as Object Set WordDoc = CreateObject ("Word.Application") WordDoc.Visible = True WordDoc.Documents.Open "C: \ Users \ Taryn \ Desktop \ BusinessDocument.docx" Set WordDoc = Nothing

Eller så kan du anpassa funktionen Öppna Excel -fil ovan för att skapa en funktion för att öppna ett Word -dokument från Access VBA.

wave wave wave wave wave