I would like to execute a macro (VBA Code for formatting the sheet) in an excel sheet that i create from code. The approach I use right now is put the macro in the workbook_open
event and open the Excel sheet from code. That applies the formatting and I save it later. But this slows down the process a lot.
I would like to know if there is way I can execute a macro using the DocumentFormat.OpenXml SDK or some other .net class without actually opening the excel file thus improving performance.
I have gone through a lot of internet material , but all in vain. Maybe I am just too much into it that I am just overlooking a very simple solution.
Kindly advise.
Thanks
I would like to just point out for reference. The comment from Tim is the answer to this, for anyone looking for an answer. I cannot mark a comment as answer so just re writing it. Will mark it as answer until I find some better way to do it.
You'll have to open the file if you want to format it... – Tim Williams
Related
If possible, also run through all modules in an excel application.
Flowchart would be something useful. I have never seen something similar for code, but there are a few VBA tools, that you may find interesting. These are the ones that I know: http://www.vitoshacademy.com/vba-professional-tools-for-vba
In general, concerning code, MZ-Tools has a good option to show the statistics of the used code. This is how it looks like:
Then you can save it as a *.txt file, edit it a bit and load it into Excel. From there you can make your own charts easily, if you need it.
My personal workbook (PERSONAL.xlsm) has stopped allowing me to view the code or any details of the modules I have saved there. It also will not allow me to run any of the Macros it once included. I don't know if they got deleted or are hiding somewhere (but I am hoping it is the later). I have not done anything out of the ordinary. Before this issue was happening all I had done with excel today was run one of these macros (without issue), make an edit to include the solver in a macro, and save it.
In addition to this problem there are a few others that seem to accompany it:
Occasionally when I close excel without saving a file, excel crashes.
If I attempt to record a macro (either in the Personal Workbook or to
another location) one of the following happens:
a. Excel crashes.
b. Excel gives me an Invalid Name Error (despite the name being perfectly valid.
It is worth noting that macros not saved in the Personal Workbook work just fine. I am very stumped and cannot find a solution to this problem anywhere. I have tried the obvious (rebooting my computer), the not so obvious (restoring previous versions of files), and the weird (disabling and enabling random things in the excel options section). Please, if you have a solution let me know!
Thank you in advance, all and any suggestions are appreciated!
I had a similar problem a while ago. I had to:
close Excel
re-name PERSONAL.xlsm to something else (like temp.xlsm)
open Excel and verify it does not "see" or attempt to open PERSONAL
create a new PERSONAL.xlsm
copy all VBA from temp.xlsm to the new PERSONAL.xlsm
Can't comment yet, so i apologize in advance.
It is definitely Excel at fault, it happens to me so often (on big files including VBA) that my before_save saves a copy of the file with time in its name, and all module's, userform's, sheet's code as *.frm, *.cls, *.bas.
I usually can also open corrupt files by holding SHIFT key (force designer mode) and then copy manually stuff.
Is it possible to save any file with VBA code?
Speciffically I a trying to save an already existing PDF file to a different lacation. The macro is run within excel workbook.
I have been browsing net for the answer, yet resultlessly, maybe I am asking wrong questions.
I would appreciate any help, pointing to tge right "key words" would be much appreciated as well.
There should be so many options for you FileCopy, Move, Name etc. are a few.
However, Ron De Bruin, has a great article on this, http://www.rondebruin.nl/win/s3/win026.htm
The code has worked on this machine previously. I worked from home yesterday on a machine which hasn't had the December 2014 Office updates removed.
I get the same error when running a little for loop which you can see commented out. Any suggestions? The sheet exists. Unhidden. Not password-protected.
Thank you!
It's happening early in the code, the worksheet might be corrupted. Copy and Paste that sheet to a new sheet and try again.
I know it's not a very in depth solution but I would try this before going crazy with different strategies.
Thank you all for the suggestions. I was able to solve this problem by following a bit of guidance from elsewhere, however.
I put a Worksheet.Select line in at the start of each Sub - just a simple line of code with no impact. Voila. Working since.
I'll stick to making mods on the one machine I use most frequently... for now.
I have just begun programming in VBA and despite my researching efforts have a quick question for the community...
Is it possible to perform the sharepoint action "Export to Spreadsheet" using a VBA macro?
I want to export to excel and create a few pivot tables if you are wondering where I am going with this.
A push in the right direction would be extremely helpful... I wish I had some code to post but I am still in the planning/researching stage.
I would first like to thank #Tim Williams for directing me towards the support.microsoft.com/kb/930006 link as I believe I have found a solution to my question. (If I had enough reputation your comments would be upvoted!)
I was able to generate an .iqy file from the "Export to Spreadsheet" command which I have successfully transferred into a VBA web query. Alternatively, I was able to simply save the .iqy file and open it with the VBA code. Both have successfully populated my spreadsheet so I can now do the reporting I was looking to do.