LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default On Open macro not running correctly

Hi. I'm trying to get the code below to run when the workbook is
opened. It runs just fine when I step through the code, but when I
put the code into the workbook to run when it's opened, it messes up.
This macro is supposed to open another workbook on our network
(QueryBuster 5.21.15b.xlsm), and then do a couple processes to update
the local workbook (QB Launcher), and then close the network workbook.
It does open the network workbook just fine, but it's supposed to copy
column H from the local workbook and insert it into the network
workbook. But it's just copying the column from the local workbook
and inserting it into itself. The macro is also supposed to then copy
cells from the network workbook and paste them into the local
workbook, and then close the network workbook. But it's closing the
local workbook instead.

Why would this macro run just fine when stepped through or as a stand
alone macro, but then mess up when put inside the Workbook Open
routine?

Thanks for any advice.

Sub UpdateQB()
'
' UpdateQB Macro
'
Dim LastRow As Long

' Turn display alerts off temporarily
Application.DisplayAlerts = False

' Unfilter data in Personal QB file and rename sheet to QueryBuster1.
Sheet will
' be deleted later after updated QB data is imported.

Sheets("QueryBuster").Select
On Error Resume Next
ActiveSheet.ShowAllData

' Open main QB, copy ProView column from local QB file to main QB
file. This will leave the sheet macro alone.
Workbooks.Open Filename:= _
"QueryBuster 5.21.15b.xlsm" _
, UpdateLinks:=0
Windows("QB Launcher.xlsm").Activate
Sheets("QueryBuster").Select
Columns("H:H").Copy
Windows("QueryBuster 5.21.15b.xlsm").Activate
Columns("H:H").Insert Shift:=xlToRight

' Finds the last row and copies the formula in column H down from row
2 to the last row

LastRow = Range("H" & Rows.Count).End(xlUp).Row
Range("H2:H" & LastRow).Formula = "=I2"
Range("A1").Select

' Copies all cells from main QB to local QB

Cells.Copy
Windows("QB Launcher.xlsm").Activate
Cells.Select
ActiveSheet.Paste

' Close main QB

Windows("QueryBuster 5.21.15b.xlsm").Activate
Sheets("QueryBuster").Select
ActiveWindow.Close

' Turn display alerts back on
Application.DisplayAlerts = True


End Sub
 
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
Open & update another file (through macro) while running macro Nitesh Excel Programming 1 May 22nd 10 04:40 AM
Running macro on Open ETLahrs Excel Programming 2 September 29th 08 04:41 PM
Macro not running correctly Bernie Excel Programming 1 August 14th 08 11:32 PM
Macro to open files isn't updating correctly telewats Excel Discussion (Misc queries) 2 February 21st 06 09:04 PM
Auto Running a macro on open Jamie Excel Programming 2 May 24th 05 05:52 PM


All times are GMT +1. The time now is 09:49 PM.

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

About Us

"It's about Microsoft Excel"