Hi there I have thorny little problem thats causing me a major headache, I have a section of code in VB.NET where I need to close the current Excel workbook, however whenever I make the call to:
'Now force a close of the active workbook without saving
_myXLApp.Workbooks(1).Close(Excel.XlSaveAction.xlDoNotSaveChanges)
The SaveAs dialog gets displayed... How do I prevent this from happening? My understanding of the code is that making the call as above should close the workbook without any SaveAs prompt. Any assistance much appreciated.
Kind Regards
paul J.
Try this instead:
_myXLApp.Workbooks(1).Close(SaveChanges:=False) 'Instead of Excel.xlSaveAction.xlDoNotSaveChanges
This should do the trick. Any time I've closed Excel workbooks in VB.Net this is the command I use. It actually mirrors the Excel VBA Format.
Related
I am getting an error when opening excel: We found a problem with some content in XXX. Do you want us to try and recover as much as we can? if you trust he source of this workbook, click Yes."
clicking Yes, "fixes" the issue but deletes a lot of VBA code, two weeks worth.
Whatever the issue it was introduced yesterday, I do not want to redo two weeks worth of coding. Is there anyway I can view what was removed, or open the VBA in notepad++ or something without opening the excel?
I opened another excel workbook and tried all the different options for the argument XlCorruptLoad in the Workbooks.Open to open the corrupt workbook. I noticed that there were two non existing sheets created in the project explroer of the corrupt workbook that had the code in there. I am not sure if it did that s a result of what I did or it was there all along and I did not notice it
Note that the reason I had a corrupted data is because the code was extracting a list and putting it in a cell validation formula..i guess I overloaded it.
One of my excel (excel A) shut down, when I try View Macro. I have enable all macros and when I try view macro from another workbook (when excel A is closed) I can. But when I have open Excel A I can not look on any macro in any workbook. It always shut down all workbooks I have open. I edit excel A 5 day ago and it works fine.
Any idea how to fix it?
I already try reset PC, open from empty excel (open and repair, open read only, ...) Nothing helps
Thanks everybody for help. At the end i fix it this way.
Open and Repair and choose Extract Data. I have to add macro buttons again, but I can view and modify macro codes :)
I was just introduced to VBA. However, on saving my first excel file with VBA code, with .xlsm extension (I was advised to do so), and then reopening that saved file, I realized that all the VBA code had disappeared and the cells in which I had used the user-defined functions threw errors. Saving the workbook as .xlsx instead of .xlsm also didn't help. When I tried saving the VBA module, it showed that FUNCRES.XLAM is read-only and hence cannot be modified, and so try saving it at a different location. Doing so, saved an excel file which on opening showed a pop-up message that it's corrupt so can't be opened. Then I gave all permissions to FUNCRES.XLAM and it is NOT read-only. But the problem still prevailed. What should I do? Can someone please help me?
PS: It is Windows 10, Office 2016.
Your VBA code needs to be saved in a module within the same workbook in which you are working. This will probably be listed as VBAProject(Book1)
There will likely be other projects listed in the Project Explorer window of the VBA GUI, but your code will not get saved with those modules.
These are related to add-ins, and not to your workbook.
Whilst I was using Excel 2011 I had a VBA program that opened another workbook. However, having moved over to Excel 2016 it no longer works, even after changing the filepath format (obtained from another Stackflow posting). The current code reads:
I am now getting the message `
Microsoft Visual Basic Compile Error: Syntax error
Where am I going wrong? I have tried it with Workbook and Workbooks on the 'Dim' line. The second VBA program at the bottom does open the file, so I know the path is correct
Use the following method instead
Set wb = GetObject("filepath\filename.xlsm")
I have a process consisting of 15 macros. Each of them has to be run separately after closing and reopening Excel, otherwise excel crushes. It seems to be inefficient, so I am thinking of creating a macro in MS WORD, which could open an Excel Workbook, call a macro in it, close the WB, and do it again with the next macro.
I tried this: https://support.microsoft.com/ru-ru/help/177760/acc97-how-to-run-macros-in-other-office-programs
But it didn't help. Something is happening, but visually Excel doesn't open. If I try to open this WB - it will say it's opened, but I can't see it and it's definitely not faster.
Any ideas?