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.
Related
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
I have a chunck of VBA code, which opens 2 files, copy the content in each, and paste that into a third file.
The problem is, that the two files (lets say "alm" and "fiber") often are used by other users, thus when i use Set alm = Workbooks.Open(alm_path) I get an error, since Excel cannot open it. I assume it is due to the file being opened by another user, and I then have to open it as write protected. Is there any smart way to do so? I am fairly new to VBA code
As mentioned in the comments you can open the workbook as ReadOnly, an example below:
Dim alm As Workbook
Set alm = Workbooks.Open(Filename:=alm_path, ReadOnly:=True)
I have a rather large list of macros in my Personal.XLSB Workbook in Excel and I am wondering if there is a way to group them in some way so that when I search for a macro to run, I don't have to read through ~50 options. I understand that I can create the shortcut to run these macros, but it is not easy to store 50 shortcuts in the forefront of my mind. Is there a way to group similar macros in the Excel list. See the image below for the beginning of my list being referenced.
I cannot remove them from the personal workbook either as the macros are required to be accessed from most files I work with.
Workbooks saved in the %AppData%\Roaming\Microsoft\Excel\XLSTART will be opened invisible when the Excel.Application opens. By moving the macros into multiple workbooks and saving them to this location, you will in effect be "Grouping the Macros".
I would start by grouping the macros into their modules within the personal macro workbook. Next I would create the destination workbooks, copy the modules over and optionally delete the original modules. Next close Excel saving all the changes and then reopen the Application.
Public Sub AddMacroWorkbook(WBName As String)
WBName = Replace(Workbooks(1).FullName, "PERSONAL", WBName)
Workbooks.Add.SaveAs Filename:=WBName, FileFormat:=xlExcel12, CreateBackup:=False
End Sub
No, the only way that you can group them, is by being careful with how you name them (which looks like you're doing already).
Might I suggest adding them to a custom Ribbon, instead of running them from the Macro Dialog? That way you could organize them, and even show/hide certain buttons, when you need to, by what workbooks are open or worksheet is active.
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 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.