473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Excel "Open_Workbook" Macro-Refresh Data and Save

Boxcar74
Hi Everybody!!!

I have an Issue.

I have an Excel file that queries an Access db. I’m trying to have it so I don’t have to keep updating it manually everyday and save it to a network drive with the file name coming from a cell reference and the current date.

What I’ve done have the Excel file open via a Batch file and on “Workbook_Open” I run a few macro to refresh the data then remake and save it to the network drive.

My problem is the code will not wait until the refresh is completed. I belive it is trying to start to Save As… action.

The error message says:This action will cancel a pending Refresh Data command. Continue?"

A few notes on the code: Keep in mind; I’m very limited as far as VBA knowledge
1. I’m using an If statement because I only want to run if is this specific file. So if some one opens the saved version it does not update.
2. I used the With…. End With. Because running this on it own (no batch file) it will wait until the refresh is done before saving. I have no Idea why, but it does.
3. I have one line of code in a module and the rest is in the “Workbook_Open” code. I read somewhere that this is the best way to save to a network drive.


In Module
Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long

In Workbook
Private Sub Workbook_Open()
If ActiveWorkbook.Name = "002 Printer Monitoring.xls" Then

With Worksheets(1).QueryTables(1)
ActiveWorkbook.RefreshAll
End With

Dim CurrentPath As String

''Store the current path
CurrentPath = CurDir

''Change the path to the one I want
SetCurrentDirectory "\\server\boxcar\
Dim newFile As String, fName As String

''Saves filename as value of A10 plus the current date.
fName = Range("A10").Value
newFile = fName & " " & Format$(Date, "mmddyyyy")

ThisWorkbook.SaveAs Filename:=newFile

''Change the path back
SetCurrentDirectory CurrentPath

ActiveWorkbook.Close
Application.Quit

End If
End Sub
------------------------------------

I know has to be a poor way to do this process. I’ve been putting the code together piece by piece and trying all different ways to get it to work. I don’t think I it is very well formated.

So any suggestions are welcome!! PLEASE!!

But my real questions is why am I getting the error message?

If it is because of the change directory and save commands.
How do I get it to wait before moving on to the next step?
(I tried the “Application.Wait” code but if pauses the refresh)

Thanks for any advice and feedback!!!

-- Boxcar
Aug 30 '07 #1
0 5677

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: farsta_online | last post by:
Hi, With ASP I store the result from form (textboxes and checkboxes) in a Access 2000 database. Now I want to use a Excel worksheet for presenting the data. What I want is partly to online...
7
by: palgrave | last post by:
Hi, How do you create an html link from a web page to a read-only excel spreadsheet without the browser asking if the user wants to open it or save it?
4
by: Gary Wright | last post by:
I have an Access 2K database split into front and back. Quite often the users want to do some data analysis that I have not created a report for so they want to export some subset of the data into...
0
by: Bernard O'Flynn | last post by:
Hi I'm trying to get the datagrid to excel export working. I've used the usual code examples that are floating around and it all works fine. The only problem is that I have multiple languages in...
1
by: Barbara Alderton | last post by:
I’m relatively new to .NET. I would like to write a VB.NET app (I read that using C# isn't as elegant when dealing with Office products) that reads in Excel files (forms) of both 2000 and 2003...
4
by: Bernie Yaeger | last post by:
I'm using the following function (I'm displaying the guts of it only) to convert a datatable to an excel spreadsheet: For Each mrow In dt.Rows rowindex += 1 colindex = 0 For Each col In...
2
by: | last post by:
Greets, How does one connect to a local excel file using data wizard is it possible? I'm trying to connect to an excel file and populate a dataset and combo box with the data from excel TIA
1
by: Pk | last post by:
Hi, I have an data in multiple excel worksheet which i wan to upload into sql server through asp code. Please help me how can i use server.createobject("excel.application") help me its...
3
by: S_K | last post by:
Hi, I have a problem when I try to save a .CSV file from an ASP.NET web page and the client has Excel open already. The symptoms are: 1) The web page is currently displaying the Excel...
0
by: jayce | last post by:
Hi I am using an ADODB connection to link up an Access database to my core spreadsheet tool. I have created a loop to repeatedly: - download data from Access - analyse it in Excel, with data...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.