VBA code to Launch and then Export data to a specified Excel worksheet

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Hi all,

I've been searching around the net looking for some code to help me do the following.

I have a command button that runs a series of queries. At the end of the code for the button I would like to add a section that takes the data from the final query, launches excel, and then exports it into a specified sheet. The export must clear and overwrite any existing cell values in the specified sheet, but must not remove the dynamically defined ranges for the various columns that I have already added.

Any help would be great, thanks all
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Thanks mate, here is the code for my command button

Code:
Private Sub btnquery_Click()
DoCmd.SetWarnings False
On Error GoTo Err_btnquery_Click
    Dim stDocName As String
    stDocName = "CTSelectedData"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
    
    stDocName = "SelectedData_Crosstab"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
    
    
Exit_btnquery_Click:
    Exit Sub
Err_btnquery_Click:
    MsgBox Err.Description
    Resume Exit_btnquery_Click
DoCmd.SetWarnings True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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