echelon99
05-14-2015, 09:46 AM
Hi guys, very new to coding, and was basically thrown in the deep end. So apologies in advance for my extreme lack on knowledge, and would really appreciate specific code.
So this is how the export functionality is set up in the form, at the moment, anyway
Private Sub cmd_export_Click()
Me.frm_ORE_All.SetFocus
'DoCmd.GoToControl "OpERA ID"
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy
Dim xlapp As Object
Set xlapp = CreateObject("Excel.Application")
With xlapp
.Workbooks.Add
.ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
False
.Cells.Select
.Cells.EntireColumn.AutoFit
.Visible = True
.Range("a1").Select
End With
End Sub
AND basically it exports the data into a xls spreadsheet. I woud like it to go one step further, and save the spreadsheet automatically as soon as its generated. I tried adding the following code:
.Range("a1").Select
Dim xlWb As Workbook
Set xlWb = .Workbooks.Add
xlWb.SaveAs ("C:\Risk\Event Quarterly Trending" & "\" & Text1.Text & ".xls")
End With
End Sub
Doesn't seem to be working so far. Anyone give me specific ways out of this?
So this is how the export functionality is set up in the form, at the moment, anyway
Private Sub cmd_export_Click()
Me.frm_ORE_All.SetFocus
'DoCmd.GoToControl "OpERA ID"
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy
Dim xlapp As Object
Set xlapp = CreateObject("Excel.Application")
With xlapp
.Workbooks.Add
.ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
False
.Cells.Select
.Cells.EntireColumn.AutoFit
.Visible = True
.Range("a1").Select
End With
End Sub
AND basically it exports the data into a xls spreadsheet. I woud like it to go one step further, and save the spreadsheet automatically as soon as its generated. I tried adding the following code:
.Range("a1").Select
Dim xlWb As Workbook
Set xlWb = .Workbooks.Add
xlWb.SaveAs ("C:\Risk\Event Quarterly Trending" & "\" & Text1.Text & ".xls")
End With
End Sub
Doesn't seem to be working so far. Anyone give me specific ways out of this?