I have a form with a subform in a datasheet view which and I would like them both to be exported into same excel file.
I am exporting the subform using this code I found, which works great but I would like to add to it the main form data as well.
Private Sub Command457_Click()
On Error GoTo Command13_Click_Err
Me.ProstojeSubform.SetFocus
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy
Dim xlapp As Excel.Application
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
Command13_Click_Exit:
Exit Sub
Command13_Click_Err:
MsgBox Error$
Resume Command13_Click_Exit
End Sub
I can export the form itself using OutputTo or the built in export but not sure how to combine them into one excel file.
CodePudding user response:
Can populate cells of worksheet by direct reference .Range("A1").Value = Me.textboxname
.
Then need to paste the subform data to a lower row. Select cell before pasting.