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
Related
I have multiples excel workbooks that will be stored in a share drive and each of them will be opened from different PCs on the same time.
ie:
wb1 open from PC1.
wb2 open from PC2.
wb3 open from PC3.
...
Users will update value in cell A1 for each workbook from different PCs. And there will be a main workbook which store the value from each workbooks.
After users updated the value, I want to create a "send" button on each excel workbook to send the value to the main workbook and the main workbook will display the value from different workbooks once user click on the "send" button.
Also, I want to have a "revise" button at the main workbook. When the button is clicked, the values in cell A1 will be cleared and cell A2 will show "Please Revise" for all workbooks.
Is this possible? As all the workbooks are opened at the same time from different PC.
As I understand it, what you are asking for is not possible with current Office editions. At my previous job we had Excel files on a shared drive that were accessed everyday by multiple computers/users. One user cannot make edits to an Excel file while it is in use by another user.
If you want multiple users to be able to make edits to a live document at the same time, you might try Google sheets instead. They have an application very similar to Excel that will probably support what you are trying to do.
I currently have a macro which creates another workbook and adds a button to it. I've assigned a macro to the button, but I believe I still need the master workbook to actually run the macro.
Is there a way to have the macro run on the new workbook without referring to the master workbook? In other words, is it possible to programmatically add a button to a new workbook with a macro and have it be independent of the original workbook?
Thanks in advance!
I'd go like this:
have your "master" workbook with a template worksheet whit both an ActiveX button and its corresponding code in its code pane
say its name is "TemplateSheetWithButtonAndCode"
in your macro use
Worksheets("TemplateSheetWithButtonAndCode").Copy
ActiveWorkbook.SaveAs "c:\MyFolder\MyWorkbooK"
this will generate a new workbook with a copy of your "template" worksheet as its only worksheet, along with necessary code to have the button work
Place the button on a template worksheet. Place the button's associated macro in that worksheet's code area.
If you export the worksheet to another workbook, you will also be exporting the button and the macro.
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.
Stated simply my question is as follows Is it possible for a button on a worksheet in a normal excel workbook (.xlsx not .xlsm) to trigger a macro in another file specifically an installed excel add in (.xlam).
Here is some background on why I want to achieve this. I have a workbook that many users need to be able to view but only some need to be able to update by filling in a form on another sheet and calling a macro in an add in. The worksheet should not contain any macros to avoid security warnings when opened by normal users. I can do this by having a ribbon button in the add in that the user clicks which will then check that the correct workbook is open and that the form is filled in etc. before executing the update code. However the interface would be nicer if the button instead of appearing on the ribbon was on the worksheet just below the form. Therefore my question is it possible to trigger an external macro from a button click in a non macro enabled workbook.
Yes, you can assign an external macro (which should be .xlsm file) to a non-macro-enabled workbook (.xlsx) button. My xlsm macro resides in the same directory as the xlsx workbook for simplicity. (Note: I am using Excel 2010)
Firstly, you must open your xlsm macro in the same instance of Excel window (i.e. do not open a new instance of Excel) so that your xlsx workbook will be able to see/access it.
Right-click on your xlsx workbook button and select "Assign Macro..."
Make sure you select Macros in: All Open Workbooks
All macros in open workbooks will be shown (this is why it is important to do step 1).
Select the desired macro from the list then click OK.
I don't see how you can execute a macro from a control in a non-macro-enabled workbook.
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.