Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default auto_open macro not performing as expected

I have the following code as an auto_open macro in workbook A:

Sub auto_open()

Dim retry_master, retry_cdc As Workbook
Dim cdc, bookname As String

cdc = Worksheets("Sheet1").Range("E5").Value

Workbooks.OpenText Filename:="O:\Retry_Reports\retry_report_" & cdc &
".rep", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1),
Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1),
Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20,
1)), _
TrailingMinusNumbers:=True

bookname = Workbooks("retry_report_" & cdc & ".rep").Name

For Each cell In Range("A1:A1000")
If cell.Value = "End" Then
totalre = cell.Offset(0, 5).Value
withre = cell.Offset(1, 5).Value
withoutre = cell.Offset(2, 5).Value
scanned = cell.Offset(3, 4).Value
End If
Next cell

Workbooks(bookname).Close

Workbooks.Open ("O:\Operations\Retry Report " & Year(Now - 1) & ".xls")

Set retry_master = Workbooks("Retry Report " & Year(Now - 1) & ".xls")

month1 = Month(Now - 1)

Select Case month1
Case 1
month2 = "January"
Case 2
month2 = "February"
Case 3
month2 = "March"
Case 4
month2 = "April"
Case 5
month2 = "May"
Case 6
month2 = "June"
Case 7
month2 = "July"
Case 8
month2 = "August"
Case 9
month2 = "September"
Case 10
month2 = "October"
Case 11
month2 = "November"
Case 12
month2 = "December"
End Select

For Each cell In retry_master.Worksheets("Sheet1").Range("A1:A1000" )
If cell.Value = month2 Then
For Each cell1 In Range(cell.Offset(0, 1).Address,
Range(cell.Offset(0, 40).Address))
If Day(cell1.Value) = Day(Now - 1) And Month(cell1.Value) =
Month(Now - 1) And Year(cell1.Value) = Year(Now - 1) Then
cell1.Offset(1, 0).Value = totalre
cell1.Offset(2, 0).Value = withre
cell1.Offset(3, 0).Value = withoutre
cell1.Offset(5, 0).Value = scanned
End If
Next cell1
End If
Next cell

retry_master.Close savechanges:=True


End Sub

I basically just retrieves data from workbook B and writes it to workbook C.
When I open workbook A, the code runs without error. It even gathers the
data from workbook B. THe problem is that when I open workbook A and let the
Auto_Open code do its thing, it doesn't write the dat to workbook C.
However, if I open workbook A and don't allow the code to auto run, and then
run the code from within the Visual Basic Editor, or step through it,
everything in the code is accomplished without error. It's the wierdest
thing that I've come accross. Can any one help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default auto_open macro not performing as expected

Eric

put a msgbox at the start of the code. Save the workbook and close it. Now
open the workbook again to activate the Auto_Open code. When the message is
displayed, press Ctrl-Break and select debug. Now step through the code
checking which workbook is active at what stage and the values of the
variables.

Regards

Trevor


"Eric Winegarner" <Eric wrote in
message ...
I have the following code as an auto_open macro in workbook A:

Sub auto_open()

Dim retry_master, retry_cdc As Workbook
Dim cdc, bookname As String

cdc = Worksheets("Sheet1").Range("E5").Value

Workbooks.OpenText Filename:="O:\Retry_Reports\retry_report_" & cdc &
".rep", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False,
Semicolon:=False, _
Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1),
_
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1),
Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1),
Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20,
1)), _
TrailingMinusNumbers:=True

bookname = Workbooks("retry_report_" & cdc & ".rep").Name

For Each cell In Range("A1:A1000")
If cell.Value = "End" Then
totalre = cell.Offset(0, 5).Value
withre = cell.Offset(1, 5).Value
withoutre = cell.Offset(2, 5).Value
scanned = cell.Offset(3, 4).Value
End If
Next cell

Workbooks(bookname).Close

Workbooks.Open ("O:\Operations\Retry Report " & Year(Now - 1) & ".xls")

Set retry_master = Workbooks("Retry Report " & Year(Now - 1) & ".xls")

month1 = Month(Now - 1)

Select Case month1
Case 1
month2 = "January"
Case 2
month2 = "February"
Case 3
month2 = "March"
Case 4
month2 = "April"
Case 5
month2 = "May"
Case 6
month2 = "June"
Case 7
month2 = "July"
Case 8
month2 = "August"
Case 9
month2 = "September"
Case 10
month2 = "October"
Case 11
month2 = "November"
Case 12
month2 = "December"
End Select

For Each cell In retry_master.Worksheets("Sheet1").Range("A1:A1000" )
If cell.Value = month2 Then
For Each cell1 In Range(cell.Offset(0, 1).Address,
Range(cell.Offset(0, 40).Address))
If Day(cell1.Value) = Day(Now - 1) And Month(cell1.Value) =
Month(Now - 1) And Year(cell1.Value) = Year(Now - 1) Then
cell1.Offset(1, 0).Value = totalre
cell1.Offset(2, 0).Value = withre
cell1.Offset(3, 0).Value = withoutre
cell1.Offset(5, 0).Value = scanned
End If
Next cell1
End If
Next cell

retry_master.Close savechanges:=True


End Sub

I basically just retrieves data from workbook B and writes it to workbook
C.
When I open workbook A, the code runs without error. It even gathers the
data from workbook B. THe problem is that when I open workbook A and let
the
Auto_Open code do its thing, it doesn't write the dat to workbook C.
However, if I open workbook A and don't allow the code to auto run, and
then
run the code from within the Visual Basic Editor, or step through it,
everything in the code is accomplished without error. It's the wierdest
thing that I've come accross. Can any one help?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto_Open Macro Trying to Excel Excel Discussion (Misc queries) 2 April 13th 07 07:08 AM
Force read-only in auto_open macro hhalle Excel Discussion (Misc queries) 0 August 20th 06 10:44 AM
Help with SaveAs Macro on Auto_Open Daen Excel Programming 3 September 15th 04 11:08 PM
Auto Open macro not performing as expected Dave Peterson[_3_] Excel Programming 2 July 23rd 04 08:39 PM
Auto_Open vs. macro John Wilson Excel Programming 0 September 22nd 03 05:44 PM


All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"