Saving Non-VSTO copy of VSTO Workbook - vb.net

I am trying to save a ListObject from a .NET 3.5 Excel 2007 VSTO Workbook to a new sheet (done) and save that new sheet to a new workbook (done) without that workbook requiring the VSTO customization file (!!!!!).
Has anyone had any luck with this? The only way I've had any success is just saving as a CSV file but that's not exactly acceptable in this case. I'd rather not save to a CSV just to copy back to a XLS file.
worksheet.SaveAs(saveDialog.FileName, Excel.XlFileFormat.xlOpenXMLWorkbook)

If I understand correctly, you do not want the new workbook file to depend or load any VSTO customization?
Try this MSDN link to remove VSTO customization assemblies from workbooks.

Ok this didn't end up working for me and here's why. The answer is still correct but I want to clarify for future users.
I have a ListObject I wanted to save in an external workbook using VSTO. Creating a new Worksheet and using SaveAs would rename the current Workbook to that and therefore I would have to close the entire workbook to remove the Customization.
What I should have done from the beginning is this:
Create the Worksheet and populate the ListObject on said Worksheet. Then use .Copy() with no parameters to create a new workbook. How do i find the workbook then though? I simply named the Worksheet Now.Ticks.ToString() and looked for any open workbook with the ActiveSheet.Name as Now.Ticks.ToString(). For this application, it doesn't need to be more in depth then that. I the saved THAT workbook and then closed it. Since the workbook was created with Copy it had no customizations on it and problem solved.

Related

Excel 365 Formulas - How to save LAMBDA function permanently (for all existing and new files)?

I would like a global solution every time I start Excel365 with my key add-in also firing up.
I defined several LAMBDA custom functions, saved them in my add-in, and I would like to make them available globally - not just only for the current workbook. Is it possible? I tried saving a workbook with definition as an add-in (.xlam) but the formulas are not available. The don't seem to be available when as an add-in. When I am in the add-in parent file on the desktop, all is good and everything is running. But once I post the file back for your as an add-in, The Lambda(s) and the defined name space go away.
You might try creating a template for excel to load when it is opened.
Customizing how Excel starts so it utilized the template.
My additional work around is also simple. If the LAMBDAs were saved in the original Workbook with "Workbook" as the saved parameter. Then each of those worksheets in the original LAMBDA workbook is "infected" with all of the workbook LAMBDAs. Therefore, I simply copy a blank worksheet from the original Workbook to the "new" workbook. Then by virtue of "infection" the new workbook is also newly infected with all of the new LAMBDAs. It works just like COVID, who knew?

auto answer to a message box on updating links

Hi have a macro that open some excel files, take some rows and close the file.
Everything works like a charm but I need to add a small feature.
On some of the files, once open, I see the message about some reference to external files missing and the option to update or not the sources.
The following is a picture of the message.
I need to click each time on "don't update" and I'd like to authomatize this action while the macro runs.
How to do it? From my research I have found how to dismiss completely messages from excel while the macro runs but I'm not sure this will solve my issue
Since you are only reading data so open them read only and tell VBA not to update the links so it will not ask you that at all:
Dim WB As Workbook
Set WB = Application.Workbooks.Open(Filename:=MyWorkBook, UpdateLinks:=False, ReadOnly:=True)
Where WB is the workbook that gets opened and MyWorkBook is the full name (path of the workbook) e.g. C:\MyDrive\MyWorkbook.xlsx

VBA Userform read another workbook dynamically without opening it

I'm fairly new to VBA. I'm trying to create a user form where the user can select another workbook as read only and copy some of the data to the current workbook. I don't want the other workbook to open.
I found this https://www.encodedna.com/excel/copy-data-from-closed-excel-workbook-without-opening.htm but the excel document is hard coded. Is it possible to select a workbook dynamically, through a file dialog without that workbook popping up?
Thank you

Copy worksheets from multiple workbooks

I need to write a macro that can either pull a specific worksheet from every workbook in a folder without opening them (preferable if possible due to the size of these workbooks) or open each workbook one at a time and copy the worksheet.
Every post on this topic I have been able to find, the path has been static and is specified in the macro, but for the purposes of this macro there will be two different paths that this will need to work for, and those will change every week.
Can someone show me how to code the macro so that it asks for the path?
Is it possible to pull a worksheet from a workbook without opening the workbook?
Thanks,
Aaron
You can use Application.FileDialog(msoFileDialogFolderPicker) to prompt for the path.

Open workbook and select worksheet from winform

I created two projects. One project is a windows form, and the other project is an Excel workbook project. I then added the Excel workbook project to the windows form project.
The window form is a welcome page. That page has some buttons that are supposed to open the workbook on a specific worksheet. For example, the screenshot below has a button Summary Worksheet, when the user clicks that button, I want to open the Excel project, on a spreadsheet by that name.
If my welcome page form was part of my Excel workbook project or any other workbook stored on my hard drive, I would know how to open the workbook. But because they are separate projects combined into one, I have no idea how I can access my workbook from the form. I guess I would like to add a reference to the winform for Excel.
I also attached a screenshot of my VS 2012 project window.
Welcome Page
It is one solution that is holding two projects. When you build the solution then you will have the .exe for your windows form and the .xlsx and .vsto for your Excel workbook. The easiest way to do what you need is to use Excel interop, and you'll need to know the path on disk to your workbook. The code could be something along these lines:
Imports Microsoft.Office.Interop
Dim xlApp as new Excel.Application
xlApp.Visible = True
Dim xlBook as new Excel.Workbook = xlApp.Workbooks.Open("path/toyour/workbook.xlsx")
xlBook.Worksheets("Welcome Sheet").Activate
That should get you started