0

Hi, I want to write a VBA macro in Word that open an Excel file, save that Excel file to another file (to another name), and then clear all content of the original Excel file. How to do that? Thanks!

4
Contributors
3
Replies
17
Views
5 Years
Discussion Span
Last Post by Dieter123
0

You should try Google as your friend :)

Try the following -

Sub OpenExcelFile()

    Dim oExcel As Excel.Application
    Dim oWB As Workbook
    Set oExcel = New Excel.Application
    Set oWB = oExcel.Workbooks.Open("C:\Documents and Settings\MyExcelFolderHere\Import.xls")
    oExcel.Visible = True
    Set oWB = oExcel.Workbooks.Open(sPath)
    'Rest of code

End Sub

To run a macro contained in an excel file, the following -

Sub OpenExcelFile()

    Dim oExcel As Excel.Application
    Dim oWB As Excel.Workbook
    Set oExcel = New Excel.Application
    Set oWB = oExcel.Workbooks.Open("k:\Test.xlsm")
    oExcel.Visible = True
    oWB.Application.Run "Module1.ShowMsg"

End Sub

To save etc, just search for the criteria needed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.