- Jan 23, 2014
Hi There. I have found lots of discussion revolving around this error, but I did not see a solution or I am not understanding fully the nature of this issue. I am trying to open up all the Excel files in a folder and perform the same set of actions on them. It is fine until I hit the row that is commented ERROR. Any help is greatly appreciated! I am using Excel 2013 for Windows 7. Thanks in advance!
Sub Test2() 'Workbooks.Open Filename:="C:\Temp\Book1.xlsx" - did not work... 'ActiveWindow.Visible = False Application.ScreenUpdating = False Dim MyFolder As String Dim myfile As String Dim folderName As String Dim WBOpen As Workbook With Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False If .Show = -1 Then folderName = .SelectedItems(1) End If End With myfile = Dir(folderName & "\*.xlsx") Do While myfile <> "" Workbooks.Open FileName:=folderName & "\" & myfile 'With ActiveWorkbook Dim i As Long: i = 2 Dim PF, Voltage 'PF = InputBox("Enter Power Factor") 'Voltage = InputBox("Enter Line to Neutral Voltage") ActiveWorkbook.Cells(1, 14) = "Power Factor" 'ERROR ActiveWorkbook.Cells(1, 15) = 0.9 ActiveWorkbook.Cells(2, 14) = "L2N Voltage" ActiveWorkbook.Cells(2, 15) = 347 ActiveWorkbook.Cells(1, 13) = "Power (kW)" Do While ActiveWorkbook.Cells(i, 12) <> vbNullString ActiveWorkbook.Cells(i, 13) = "=(RC[-9]+RC[-5]+RC[-1])*60/1000*R1C15*(R2C15/347)" i = i + 1 Loop ActiveWorkbook.Save 'use below 3 lines if you want to close the workbook right after saving, so you dont have a lots of workbooks opened Application.DisplayAlerts = False ActiveWorkbook.Close Application.DisplayAlerts = True myfile = Dir 'End With Loop End Sub