Hello.
I am trying desperately to output data from an Access form to an excel spreadsheet. I have it working fine, but the end users would now like the ability to navagate to a workbook with a name of their choosing (it would contain the same sheets within). I think the best way is to capture the path name from the file dialog, but I am unsure how. Can anyone help? My code is below...
Dim xlobject As Object, xlsheet As Object
Call filedialog
If fileerror = False Then
Set xlobject = GetObject(datafile)
xlobject.Application.Visible = True
filenme = "Workbook1"
xlobject.Parent.Windows(filenme).Activate
Set xlsheet = xlobject.Application.ActiveWorkbook.Sheets("Sheet1"
With xlsheet
.Range("Month4"
.Value = Me.Num4
.Range("Month3"
.Value = Me.Num3
.Range("Month2"
.Value = Me.Num2
.Range("Month1"
.Value = Me.Num1
.Range("Row1Col1"
.Value = Me.I4P4
.Range("Row2Col1"
.Value = Me.I4P3
.Range("Row3Col1"
.Value = Me.I4P2
.Range("Row4Col1"
.Value = Me.I4P1
.Range("Row2Col2"
.Value = Me.I3P3
.Range("Row3Col2"
.Value = Me.I3P2
.Range("Row3Col3"
.Value = Me.I2P2
.Range("Row4Col2"
.Value = Me.I3P1
.Range("Row4Col3"
.Value = Me.I2P1
.Range("Row4Col4"
.Value = Me.I1P1
.Range("Row5Col1"
.Value = Me.I4P5
.Range("Row5Col2"
.Value = Me.I3P5
.Range("Row5Col3"
.Value = Me.I2P5
.Range("Row5Col4"
.Value = Me.I1P5
.Range("Reserve4"
.Value = Me.I4Reserves
.Range("Reserve3"
.Value = Me.I3Reserves
.Range("Reserve2"
.Value = Me.I2Reserves
.Range("Reserve1"
.Value = Me.I1Reserves
End With
On Error Resume Next
xlobject.SaveAs datafile
Set xlobject = Nothing
End If
End If
End Sub
Public xlobject As Object, xlsheet As Object, varFile As Variant, fdialog As filedialog
Global datafile As String, fileerror As Boolean, filenme As String
Public Function filedialog()
Set fdialog = Application.filedialog(msoFileDialogOpen)
With fdialog
.AllowMultiSelect = False
.Title = "Please select the Workbook!"
.Filters.Clear
.Filters.Add "Excel", "*.xls"
If .Show = True Then
For Each varFile In .SelectedItems
datafile = varFile
Next
Else
MsgBox ("You either hit Cancel or did not select a file. Please try again."
fileerror = True
End If
End With
End Function
Thank you in advance!!!
Rocky
I am trying desperately to output data from an Access form to an excel spreadsheet. I have it working fine, but the end users would now like the ability to navagate to a workbook with a name of their choosing (it would contain the same sheets within). I think the best way is to capture the path name from the file dialog, but I am unsure how. Can anyone help? My code is below...
Dim xlobject As Object, xlsheet As Object
Call filedialog
If fileerror = False Then
Set xlobject = GetObject(datafile)
xlobject.Application.Visible = True
filenme = "Workbook1"
xlobject.Parent.Windows(filenme).Activate
Set xlsheet = xlobject.Application.ActiveWorkbook.Sheets("Sheet1"
With xlsheet
.Range("Month4"
.Range("Month3"
.Range("Month2"
.Range("Month1"
.Range("Row1Col1"
.Range("Row2Col1"
.Range("Row3Col1"
.Range("Row4Col1"
.Range("Row2Col2"
.Range("Row3Col2"
.Range("Row3Col3"
.Range("Row4Col2"
.Range("Row4Col3"
.Range("Row4Col4"
.Range("Row5Col1"
.Range("Row5Col2"
.Range("Row5Col3"
.Range("Row5Col4"
.Range("Reserve4"
.Range("Reserve3"
.Range("Reserve2"
.Range("Reserve1"
End With
On Error Resume Next
xlobject.SaveAs datafile
Set xlobject = Nothing
End If
End If
End Sub
Public xlobject As Object, xlsheet As Object, varFile As Variant, fdialog As filedialog
Global datafile As String, fileerror As Boolean, filenme As String
Public Function filedialog()
Set fdialog = Application.filedialog(msoFileDialogOpen)
With fdialog
.AllowMultiSelect = False
.Title = "Please select the Workbook!"
.Filters.Clear
.Filters.Add "Excel", "*.xls"
If .Show = True Then
For Each varFile In .SelectedItems
datafile = varFile
Next
Else
MsgBox ("You either hit Cancel or did not select a file. Please try again."
fileerror = True
End If
End With
End Function
Thank you in advance!!!
Rocky