PC Review


Reply
Thread Tools Rate Thread

I can't update external data sources using vba

 
 
GrahamBaines
Guest
Posts: n/a
 
      28th Nov 2007
Hi,

I've been writing a bit of code to automate the opening, refreshing of
external data, saving and closing of spreadsheets. I'm having problems which
I think are associated with the speed of the refesh. The workbook opens fine
but when I run the code I get a warning which states:- "This action will
cancel a pending data refresh command. Cancel?".

The code I'm running is:-

Private Sub CommandButton1_Click()

Application.Workbooks.Open ("X:\ Stats 2007.xls")

ActiveWorkbook.RefreshAll

ActiveWorkbook.Save

ActiveWorkbook.Close

End Sub

I tried disabling the messages using:-

"Application.DisplayAlerts = False"

That stopped the message and the workbook opened and closed fine, but the
refresh didn't save. I tried putting a wait statement into the code to pause
the 'save' command until the refresh has had time to complete, but that had
no effect. I inserted an 'On Error' statement and forced the code to loop
back to the 'save' command until it had completed, but again to no avail.

I find it inconceivable that it isn't possible to open, refresh, save and
close a workbook from another workbook using vba, but at present it's
defeats me, any ideas? All help gratefully accepted.................

Many Thanks

Graham

 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      28th Nov 2007
perhaps you need to suspend activity while refreshing

Application.Workbooks.Open ("X:\ Stats 2007.xls")
application.enableevents=false
ActiveWorkbook.RefreshAll
application.enableevents=true
ActiveWorkbook.Save

ActiveWorkbook.Close

End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"GrahamBaines" <(E-Mail Removed)> wrote in message
news:7339B943-E7A9-4B57-83DD-(E-Mail Removed)...
> Hi,
>
> I've been writing a bit of code to automate the opening, refreshing of
> external data, saving and closing of spreadsheets. I'm having problems
> which
> I think are associated with the speed of the refesh. The workbook opens
> fine
> but when I run the code I get a warning which states:- "This action will
> cancel a pending data refresh command. Cancel?".
>
> The code I'm running is:-
>
> Private Sub CommandButton1_Click()
>
> Application.Workbooks.Open ("X:\ Stats 2007.xls")
>
> ActiveWorkbook.RefreshAll
>
> ActiveWorkbook.Save
>
> ActiveWorkbook.Close
>
> End Sub
>
> I tried disabling the messages using:-
>
> "Application.DisplayAlerts = False"
>
> That stopped the message and the workbook opened and closed fine, but the
> refresh didn't save. I tried putting a wait statement into the code to
> pause
> the 'save' command until the refresh has had time to complete, but that
> had
> no effect. I inserted an 'On Error' statement and forced the code to loop
> back to the 'save' command until it had completed, but again to no avail.
>
> I find it inconceivable that it isn't possible to open, refresh, save and
> close a workbook from another workbook using vba, but at present it's
> defeats me, any ideas? All help gratefully accepted.................
>
> Many Thanks
>
> Graham
>


 
Reply With Quote
 
john
Guest
Posts: n/a
 
      28th Nov 2007
following seemed to work ok for me:

Private Sub CommandButton1_Click()
Dim FName As Workbook
With Application
.EnableEvents = False
Set FName = .Workbooks.Open("X:\Stats 2007.xls", False)
mybook = FName.Name
With FName
.RefreshAll
.Close True 'save file
End With
.EnableEvents = True
End With
msg = MsgBox(mybook & " Refreshed")
End Sub
--
JB


"GrahamBaines" wrote:

> Hi,
>
> I've been writing a bit of code to automate the opening, refreshing of
> external data, saving and closing of spreadsheets. I'm having problems which
> I think are associated with the speed of the refesh. The workbook opens fine
> but when I run the code I get a warning which states:- "This action will
> cancel a pending data refresh command. Cancel?".
>
> The code I'm running is:-
>
> Private Sub CommandButton1_Click()
>
> Application.Workbooks.Open ("X:\ Stats 2007.xls")
>
> ActiveWorkbook.RefreshAll
>
> ActiveWorkbook.Save
>
> ActiveWorkbook.Close
>
> End Sub
>
> I tried disabling the messages using:-
>
> "Application.DisplayAlerts = False"
>
> That stopped the message and the workbook opened and closed fine, but the
> refresh didn't save. I tried putting a wait statement into the code to pause
> the 'save' command until the refresh has had time to complete, but that had
> no effect. I inserted an 'On Error' statement and forced the code to loop
> back to the 'save' command until it had completed, but again to no avail.
>
> I find it inconceivable that it isn't possible to open, refresh, save and
> close a workbook from another workbook using vba, but at present it's
> defeats me, any ideas? All help gratefully accepted.................
>
> Many Thanks
>
> Graham
>

 
Reply With Quote
 
GrahamBaines
Guest
Posts: n/a
 
      29th Nov 2007
Many thanks for the assistance, I've learned some useful new commands, both
fragments of code run without error but don't update the external data.

Cheers

G

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use data from external sources rishi Microsoft Excel Worksheet Functions 4 31st Aug 2010 08:52 AM
External data sources Microsoft Access External Data 1 9th Dec 2007 08:44 PM
external data from multiple sources =?Utf-8?B?bG91IHNhbmRlcnNvbg==?= Microsoft Excel Programming 0 20th May 2005 07:21 PM
External data sources in Excell... George Microsoft Excel Programming 2 30th Apr 2004 09:19 AM
External Data Sources Squid Microsoft Excel Misc 0 13th Jan 2004 09:55 PM


Features
 

Advertising
 

Newsgroups
 


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