• Save manipulated excel sheet with different name (

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Save manipulated excel sheet with different name (

    Author
    Topic
    #449292

    I use the following code to open a .xls file:

        Dim appExcel As Excel.Application
        Set appExcel = CreateObject("Excel.Application")
        Dim strTheFile As String
        strTheFile = CurrentProject.Path & "template.xls"
           appExcel.Workbooks.Open strTheFile
            appExcel.Visible = True
            Dim strSheetName As String
            strSheetName = "DATA"
            appExcel.Sheets(strSheetName).Select
    
    
            With appExcel
                .Range("A1").Select
                .ActiveCell.Value = rstIn!fname & "'s Team"
                .Range("a2").Value = rstIn!PxWx & " 20" & rstIn!Year
                .Range("A6").Select
            End With
    

    Now, how do I save the file with a different name?

    Viewing 0 reply threads
    Author
    Replies
    • #1101270

      Add the following declaration near the beginning of your code:

      Dim wbk As Excel.Workbook

      and change the line

      appExcel.Workbooks.Open strTheFile

      to

      Set wbk = appExcel.Workbooks.Open(strTheFile)

      You can then use a line like this to save the workbook under another name:

      wbk.SaveAs CurrentProject.Path & “newname.xls”

    Viewing 0 reply threads
    Reply To: Reply #1101270 in Save manipulated excel sheet with different name (

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel