Run code after Data Import from Google Docs

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
HI there VBA Gurus,

I am looking for some code that is triggered after a web query has run. to run the following code:

Code:
Sub A()

    Rows("1:130").Delete Shift:=xlUp
With Cells
    .Replace What:="?»?", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    .ClearFormats
End With
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
There are 3 ways I can think of:

1. Call your code in the Worksheet_Change event on the web query sheet. You may need to experiment to determine if all the data for the web query has been retrieved. One way which might work is:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
        
    If Not Intersect(QueryTables(1).Destination, Target) Is Nothing Then
        
        'All data for web query has been retrieved

        A 'call your code
    End If

End Sub

2. Call your code in the web query's AfterRefresh event. http://support.microsoft.com/kb/213187 shows how to set up the event handler.

3. Refresh the web query yourself in VBA code rather than via the Excel GUI and call your code after the .Refresh call, something like this:
Code:
Dim qt As QueryTable
Set qt = Sheets(1).querytables(1)
qt.Refresh BackgroundQuery:=False
A 'call your code
 
Upvote 0
Hi there John,

Thank you for taking the time to send me all the options, been having a bit of fun with the codes, I am going to use the 3rd option.

I take it that you have had some expiriance pulling data from Google docs? have you run into any challanges with the data? or do you have any tips I would possible use?

thank you once again, your responce is very helpfull to me.

Kindest Regards,
Mark Blackburn
 
Upvote 0
I'm glad my response was helpful. The 3rd option is the easiest to implement, because you can control when the web query retrieves the data and know that the data is complete before manipulating it.

Sorry, but I've never written any code for Google Docs, so don't know what's involved.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,487
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top