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
Related
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 ran into a strange Excel 2013 VBA behavior today and felt posting the solution to the problem may help someone else in the future.
The following command worked fine on my computer and most others but one user would get an error message. I'm using Windows 7.
Workbooks("Book1").Activate
What I found out was that the other user has 'extensions for known file types' shown. By default Windows wants to hide those. In order to get the code to work properly on all machines, I had to include the file extension in the code as shown below. When a new workbook is created and has not yet been saved, it does not need a file extension included in this command as it is not yet determined.
Workbooks("Book1.xlsm").Activate
Just guessing, but this may be related to a setting in "Folder options" of Windows Explorer.
On the View tab there is an option "Hide extensions for known file types" - this will affect how you can refer to workbooks by name in VBA.
EDIT: seems you got there already!
I've already had the file extensions enabled but it didn't work. I fixed by forcing the file and sheet to activate.
Example (while the files are still open):
Windows("file2.xlsm").Activate
ThisWorkbook.Worksheets("sheet2").Activate
I know that Activate and Select are inneficient, but if it works..
Hi in your code use two dim for workbooks like
dim currentwb,newwb as workbook
set currentwb = ActiveWorkbook
and once you create your new workbook set
set newwb = ActiveWorkbook
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.
In my database I manage different Excel files. There's a button in a Report which allows to open those files, and to do it I use this linse of code (runs the code at click on the button):
Dim str_file As String
str_file = "C:\[directory of the file]"
Application.FollowHyperlink str_file
It works, and opens the file I want. The problem is that it does not set the excel program as active, when it opens the file it shows very quickly the file but for something I don't know Excel application is hiden and Access application is active. I I've experienced some problems with popup forms that because it's a popup, you can't set an active window different from the popup, but this problem solves if you close the popup before setting an active form. I've tried also lines like these above but they don't work also:
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
I found the problem. The code in Access works well, it does what it's supposed to do. The excel files I have are ".xlsm", because I need to run some code when the file is saved, I need to update some fields on Access database. So I needed to call Access from excel, and this code runs when the file opens. So I run Excel from Access and then Access from Excel. I hope that this helps someone with that problem. Remember: if you have problems whith opening files from Access and your excel files can run code, check that all runs when you really need.
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.