Run a script after export to excel


I have button on a form that exports data in an excel forma to a folder.
After I export the data, I right click the file and choose to the script.

I want to automate the script from within Access instead of right clicking the file and running the script.  
Basically I want to remove this extra step and have it all inside of access.  

How can I do this?  

Not sure if my explanation is detailed enough.
Please feel free to ask a question.

thank you
pdvsaProject financeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm confused.  Are you saying that you want to run code that exists in the spreadsheet you just created or do you want to run code in your Access app?  If in Access, then just add it following the TransferSpreadsheet method.

Private Sub cmdYourButton_Click()
    DoCmd.TransferSpreadsheet ............
    ''your other code goes here
 End Sub

Open in new window

pdvsaProject financeAuthor Commented:
Pat, yes I want to run the code from in Access.  I have attached the script  It is a .vbs.  Should I place that code where you state above?
Create a new module in Access.
Create a new procedure in the module.
Paste the script into the new procedure.

After the transferSpreadsheet, add a command to call the new procedure.

Docmd.TransferSpreadsheet .....
Call NewProcName()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

pdvsaProject financeAuthor Commented:
Oh I see.  An expert way to do that.  Will give it a try.  

Thank you
pdvsaProject financeAuthor Commented:

Sorry to pester you once again.  
Possibly you could provide me a solution to the "variable not defined" error I get on this line:
strFil = WScript.Arguments(0)

thank you Pat.
Sorry.  I haven't done this in a while.  You need to set a reference to the Scripting runtime library.

Open any code module.
You'll see the following dialog.
Scroll to select the Scripting librarySetReference.JPG
pdvsaProject financeAuthor Commented:
Hi Pat, thank you for the follow up.  I sincerely appreciate it.  Unfortunately, that did not fix the issue.   Wondering if you have any other ideas to fix the "variable not defined" error?  I might post another question if this might be a little more complicated than I assume.  I did try to add other scripting references.  Acteually I added all the ones I could find but still had the error.  Not sure if I need to define this Wscript variable it in the first line between the ().

thank you
Variables should always be defined.
pdvsaProject financeAuthor Commented:
Ok.  Thank you Pat...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.