ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   WorkBook_Open Event (https://www.excelbanter.com/excel-programming/290630-re-workbook_open-event.html)

Squid[_3_]

WorkBook_Open Event
 
Ok, eventually I will get the code right. I think I am closer than ever
before with your help. Thanks again.. Mike

The problem now is it is copying the contents of the wrong worksheet. It
copies data from workbook Settlement.xls, sheet Settlement (first sheet in
workbook), instead of workbook Contracts1.xls, sheet Sheet1. Plus it doesnt
like my code for the combobox. What am I doing wrong again?

The code you gave me earlier this week worked perfect with a command button.
But putting it in the Workbook_Open event it doesnt want to work correctly.
What is the reason for this?

Private Sub Workbook_Open()
Dim numRows As Long

'Refresh data of Contracts worksheet in C:\CCF\Settlement4.xls from data
contained
'in worksheet Sheet1 in C:\CCF\Contracts1.xls

Workbooks.Open Filename:="C:\CCF\Contracts1.xls"
With ThisWorkbook.Worksheets("Contracts") 'C:\CCF\Settlement4.xls

'Determine number of rows in C:\CCF\Contracts1.xls Sheet1

numRows = Application.CountA(ActiveSheet.Range("A:A"))

'Copy from C:\CCF\Contracts1.xls!Sheet1 and
'Paste in C:\CCF\Settlement4.xls!Contracts
ActiveSheet.Range("A1:AI" & numRows).Copy .Range("A1")


'modify combobox properties to update listfillrange
cmbContracts.ListFillRange = "Contracts!A2:C" & numRows


End With
ActiveWorkbook.Close

'Select Settlement worksheet so this is what the user sees
Worksheets("Settlement").Select

End Sub



Tom Ogilvy

WorkBook_Open Event
 
Private Sub Workbook_Open()
Dim numRows As Long
Dim sh1 as Worksheet
Dim sh2 as Worksheet
'Refresh data of Contracts worksheet in C:\CCF\Settlement4.xls from data
contained
'in worksheet Sheet1 in C:\CCF\Contracts1.xls

Workbooks.Open Filename:="C:\CCF\Contracts1.xls"
set sh1 = Workbooks("Contracts1.xls").Worksheets("Sheet1")
set sh2 = Workbooks("Settlement4.xls").Worksheets("Contracts ")
'Determine number of rows in C:\CCF\Contracts1.xls Sheet1

numRows = Application.CountA(sh1.Range("A:A"))

'Copy from C:\CCF\Contracts1.xls!Sheet1 and
'Paste in C:\CCF\Settlement4.xls!Contracts
sh1.Range("A1:AI" & numRows).Copy sh2.Range("A1")


'modify combobox properties to update listfillrange
sh2.Parent.Worksheets("Settlement").cmbContracts. _
ListFillRange = sh2.Range("A2"). _
Resize(numRows).Address(External:=True)


End With
ActiveWorkbook.Close

'Select Settlement worksheet so this is what the user sees
Worksheets("Settlement").Select

End Sub

You don't say where cmbContract is located, so I am guessing it is in
Settlement4.xls on sheet Settlement.

--
Regards,
Tom Ogilvy


Squid wrote in message
news:cCgVb.114980$U%5.595222@attbi_s03...
Ok, eventually I will get the code right. I think I am closer than ever
before with your help. Thanks again.. Mike

The problem now is it is copying the contents of the wrong worksheet. It
copies data from workbook Settlement.xls, sheet Settlement (first sheet in
workbook), instead of workbook Contracts1.xls, sheet Sheet1. Plus it

doesnt
like my code for the combobox. What am I doing wrong again?

The code you gave me earlier this week worked perfect with a command

button.
But putting it in the Workbook_Open event it doesnt want to work

correctly.
What is the reason for this?

Private Sub Workbook_Open()
Dim numRows As Long

'Refresh data of Contracts worksheet in C:\CCF\Settlement4.xls from data
contained
'in worksheet Sheet1 in C:\CCF\Contracts1.xls

Workbooks.Open Filename:="C:\CCF\Contracts1.xls"
With ThisWorkbook.Worksheets("Contracts") 'C:\CCF\Settlement4.xls

'Determine number of rows in C:\CCF\Contracts1.xls Sheet1

numRows = Application.CountA(ActiveSheet.Range("A:A"))

'Copy from C:\CCF\Contracts1.xls!Sheet1 and
'Paste in C:\CCF\Settlement4.xls!Contracts
ActiveSheet.Range("A1:AI" & numRows).Copy .Range("A1")


'modify combobox properties to update listfillrange
cmbContracts.ListFillRange = "Contracts!A2:C" & numRows


End With
ActiveWorkbook.Close

'Select Settlement worksheet so this is what the user sees
Worksheets("Settlement").Select

End Sub






All times are GMT +1. The time now is 03:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com