How to run a vba macro for multiple excel files - excel

I am a naive user of VBA and I am looking for a VBA macro which would do the following task
Delete 3 tabs from the file and delete the first 6 rows from remanining tabs.
Perform this for all the excel files (2013) and save as xlsx in the same or different file folder.
I tried the code available on this link
Run same excel macro on multiple excel files
At the line
Filename=Dir(Pathname & "*.xlsx") , I am getting an error which says run time error "52" Bad file name or number.
I have changed this:
Pathname = "\C:\Users\Desktop\test\try\"\
Is this correct?

Not sure if it's your only problem, but
\C:\Users\Desktop\test\try\
should be
C:\Users\Desktop\test\try\ (without the first backslash)
*I realize this should be a comment--I'm under 50 rep, however.

Related

How to append one excel file as a sheet onto another excel file in alteryx

so I have about 90 different excel files that are customer reports. I have one generic excel file that's a summary page that I need to insert as a sheet into all of those other excel files. Does anyone have a way to automate this process - I'm generating the sheets through alteryx but open to solutions outside of that platform or maybe there's a simple way to do it through Excel that I'm missing.
Right now, the only option is to open each report and copy over the summary sheet and insert it that way. To do it for 90 sheets would take me over an hour so trying to shorten the time.

Opening a file with code breaks formulas?

I need to open another workbook, so I execute this code:
Set wbOpen = Workbooks.Open(PathFile)
If I open the file with this code some formulas have #names errors.
If I open the file manually (without vba) I have no errors at all.
If I open the file with this code, get the errors, save the file and open it manually, errors remain. If I validate all formulas one by one from the beginning the formulas work again.
There are no external links to any other workbooks in this file.
I don't understand at all why opening a file with VBA code is different than open it manually?
How can I find the source of this bug?

Running Multiple Excels having separate Macros without opening File

I have around 10 different excel files. For each file, I have a process saved in notepad
Every day i need to open each file, copy - paste the code from notepad to VB-excel & run the code
Is there any way I can kind of do this in batch file
Something like
Open File1
Run code of File1.
Save File 1
Repeat the same for File 2
Pls help
You should store your macro in a "Personal Workbook" described here.
The macros you store there load together with the Excel application and will be available to all workbooks you open.
In addition to the "Personal Workbook", I may even suggest automating that personal sub to open the workbooks automatically?
This could also potentially just point to a folder and For Each Workbook in definedSelectedWindowsPath
call subToAutomate()
similar to this
BIG thanks to Mr. Newman, he has certainly saved my back from a few sleepless coding problems.

How do I save an XLSM file as an XLSX file without prompting the user about lost data? [duplicate]

This question already has an answer here:
Save a *.xlsm file as *.xlsx and suppress the pop-up
(1 answer)
Closed 1 year ago.
TLDR:
How do I save a Excel-File-with-Macros as an Excel-File-without-Macros using VBA suppressing the prompt that the target format does not support macros?
I have a xlsb file (Excel 2007+ with Macros), inside is the content and a button that should save that file as an xlsx (Excel 2007 WITHOUT Macros). So far, so good. I'll use ActiveWorkbook.SaveAs FileName:=name, FileFormat=xlOpenXMLWorkbook, Password="xyz"
But that always generates a prompt that tells the user that saving data in the target format means loosing the macro data and if he/she wants to continue...
I've tried Application.DisplayAlerts = False and ThisWorkbook.CheckCompatibility = False. I've also recorded the same action with the MacroRecorder that also seems unable to skip the upcoming prompt.
My last try was a copy of the content using ThisWorkbook.Sheets.Copy and trying to remove the VBProject data. Tried various ways but it seems that the vb-project data can't be really removed. After executing remove and stuff like that the debugger shows always three items of vb-project-data.
I'll check this tomorrow, but it looks very much like the code I've tried...
Macro to save active Sheet as new workbook, ask user for location and remove macros from the new workbook
You can use
Thisworkbook.SaveCopyAs ([filename.xlsx]).
This creates a copy of the workbook without the macros in it and without the alert. [filename.xlsx] should of course be replaced by your own file path. Use the xlsx extension to make sure you don't copy the macros.

Access two excel files using single macro

I have macro, using which i am trying to open a excel file then make some validation in the file that is opened. And Open another excel file and put the validation results(of excel file 1) in the form of report in the 2nd Excel.
So the task i have to do here is:
Open Excel file 1
Script to validate data in excel file 1.
Open Excel file 2
Enter the results in it.
Here i am able to open two excel files but not able to create pointers to them. Such as
if i use Sheets("Sheet1").Range("A1").value 'this picks data from Excel file 1.
But to access Excel file 2 what do i need to write, is this something like this:
Sheets("!Sheet1").Range("A1").value
Please help me to fix this. Thanks.
Application.Workbooks("create-a-macro").Worksheets(1).Range("A1").Value = "Hello"
Visit http://www.excel-easy.com/vba/workbook-worksheet-object.html

Resources