Hi Guys,
I've got an Outlook form that opens Excel and puts details of selected email there. I need to figure out how to find last unused row in this Excel file.
Normally the procedure goes more or less as show below but this work as long as we are within Excel application:
For Outoolok <-> Excel relation it returns 'Object Required' error. The code goes as follows:
Cheers,
Witek
I've got an Outlook form that opens Excel and puts details of selected email there. I need to figure out how to find last unused row in this Excel file.
Normally the procedure goes more or less as show below but this work as long as we are within Excel application:
Code:
Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For Outoolok <-> Excel relation it returns 'Object Required' error. The code goes as follows:
Code:
Private Sub CommandButton1_Click()
Dim xlApp As Object
Dim xlWB As Object
Dim Submitter As String
Dim From As String
Dim DateStamp As Date
Dim TaskName As String
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open("[URL="file://\\networkdrive\something\ekselek1.xlsx"]\\networkdrive\something\ekselek1.xlsx[/URL]")
Submitter = SubmitterBox.Value
From = FromBox.Value
DateStamp = DateStampBox.Value
TaskName = TaskNameBox.Value
Select Case True
Case OptionButton1
Region = "Americas"
Case OptionButton2
Region = "Europe"
Case OptionButton3
Region = "Asia"
End Select
Select Case True
Case OptionButton4
MainCat = "Data_Request_New_Report"
Case OptionButton5
MainCat = "Data_Request_ExistingReport"
Case OptionButton6
MainCat = "Changes_to_report"
Case OptionButton7
MainCat = "Manual_upload"
Case OptionButton8
MainCat = "Investigation"
Case OptionButton9
MainCat = "Static_maintenance"
End Select
'With xlWB.Sheets("Sheet1")
NextRow = xlWB.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row '<------------------ DOES NOT WORK - returns 'object required'
xlWB.Sheets("Sheet1").Range("A" & NextRow).Value = Submitter
xlWB.Sheets("Sheet1").Range("B" & NextRow).Value = From
xlWB.Sheets("Sheet1").Range("C" & NextRow).Value = DateStamp
xlWB.Sheets("Sheet1").Range("D" & NextRow).Value = TaskName
'End With
Unload Me
xlWB.Close SaveChanges:=True
End Sub
Cheers,
Witek