saving any file with VBA code - vba

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

Related

Is there a tool which visualizes VBA code via e.g. a flow chart?

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.

Excel Personal Worksheet VBA Module's won't allow me to view code

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.

Executing a macro in Excel sheet

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

Sharepoint "Export to Spreadsheet" Question

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.

Excel VBA File not Found

During the development of some Excel vba code, in about every other iteration where I go in, add some code and then save the file, the next time I open it, I get a "File not Found" error. The macro is set to automatically run the code upon opening the file.
To fix it, I copied all the code - modules and classes plus the startup code - to a fresh blank excel file. I save the excel macro file and it runs fine.
This happens for both Excel 2003 and 2007. What is happening here?
My psycho powers tell me you are relying on relative paths while changing the current directory.
I'm seeing a similar phenomenon, though I'm not sure the cause is the same.
Yesterday, every time I added a Workbook_Open procedure to my workbook, saved it and reopened it, I got the "File not found" error (no particular file specified). followed by "We found a problem with some content in [workbook name]. Do you want us to try to recover as much as we can?". If I said Yes to recovering, I found that all the VBA code was gone from the workbook.
It turned out that this was caused by my virus checker (BitDefender), which considered my code to be malware and was removing code from the workbook. I tried it on a PC with a different virus checker (BullGuard) and it did something similar. At least BullGuard had the decency to tell me it was modifying my file. BitDefender didn't give me any clue at all!
On a general point, as someone who does VBA work for many different clients, I'm finding more and more problems with virus checkers getting in my way.
Not sure if you have solved your problem.
One possibility is that one of your module is too long.
VBA is a compiled size limit for 64kb. It is "supposed" to warn you if you exceed that, but often it fails.
Find out the longest Module that you have, move some function out to another module and see if it helps.
I have this often.