change excel worksheet name

tommy_mo

Registered User.
Local time
Yesterday, 19:16
Joined
Oct 5, 2006
Messages
42
I've had look through the forums and have not been able to get a good answer for what I'm trying to do. I have the output to excel part down, but it seems that excel names the worksheet the query name by default. I would like to name it something else. What is the best way to do it? Cheers for any help you can give me. -Tom

Code:
Private Sub cmdExportToExcel_Click()
On Error GoTo Err_cmdExportToExcel_Click

    Dim strQueryName As String
    Dim strExcelDetail As String
    Dim strDTSaved As String
    Dim strDirectoryPath As String
  
    

    strDirectoryPath = "\\Odo\odo_shared\JET 4\Raw\PDA Light Log\" + CStr(Me.Combo78)
    strDTSaved = Format(DATE, "MMdd")
    strQueryName = "LightlogExportToExcel"
    strExcelDetail = strDirectoryPath & "\" & Me.Combo78 & " " & "Light Log" & " " & strDTSaved & ".xls"

    
    If Len(Dir$(strDirectoryPath & "\.", vbDirectory)) <> 0 Then
    GoTo output
    
    Else
    MkDir (strDirectoryPath)
    MsgBox "A folder has been created on the network at location: \\Odo\odo_shared\JET 4\Raw\PDA Light Log\" + CStr(Me.Combo78)
    GoTo output
    
    End If

output:
'strExcelDetail = "c:\temp\ Light Log" & " " & strDTSaved & ".xls" ' This excel file will be saved as C:\Temp\Output Current Date and Time .xls
    DoCmd.OutputTo acQuery, strQueryName, "MicrosoftExcel(*.xls)", strExcelDetail, True, ""
     

Exit_cmdExportToExcel_Click:
    Exit Sub

Err_cmdExportToExcel_Click:
    MsgBox Err.Description
    'MsgBox "Perform a HotSync operation before saving."
    Resume Exit_cmdExportToExcel_Click
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom