Macro extraction process has some exception:Exception from HRESULT: 0x800A9C68

I am getting error while running Macro in excel file:
Run code error ‘9’:
subscript out of range

Windows(“SourceData.xlsx”).Activate
Sheets(“Sheet1”).Select
Range(“C7:M34”).Select
Selection.Copy
Windows(“File.xlsm”).Activate
Sheets(“Sheet”).Select
Range(“C7:M34”).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Line number 6 —> Sheets(“Sheet”).Select

is the sheet name valid?

Try with Sheets(“Sheet1”).Select

yes sheet name is correct.
i pasted all code again, can you check it once.
Windows(“SourceData.xlsx”).Activate
Sheets(“AN”).Select
Range(“C7:M34”).Select
Selection.Copy
Windows(“Source.xlsm”).Activate
Sheets(“AN”).Select
Range(“C7:M34”).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Windows(“SourceData.xlsx”).Activate
Selection.Copy
Windows(“Source.xlsm”).Activate
Range(“C7”).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-27
Range(“A1:M1”).Select
Sheets(“CC”).Select
this same code writing multiple times for all sheets i have in excel file by changing the sheet name.

Hi @Rama_Krishna_Gadde

Pls check Macro enable:
To enable Macro settings in Excel > navigate to the “File” tab, select “Options”, then choose “Trust Center” followed by “Trust Center Settings”; within the Macro Settings section, select the desired level of macro enablement (usually “Enable all macros”) and click “OK”

Already macro enabled in excel. @prashant1603765

Hi @Rama_Krishna_Gadde
The HRESULT: 0x800A9C68 exception occurs due to issues with Excel COM interactions, such as improper initialization, unclosed Excel instances, recovery dialogs blocking actions, or multiple instances of Excel running simultaneously.

or Excel being busy due to auto-syncing with OneDrive

@Rama_Krishna_Gadde

when you get the error try to open in debug on macro and check which line it is failing

subscription out of range comes when the sheet or range are invalid…
it might be because of activates as well as I see you using two excels but no open command is present

cheers

cheers

Ideally you should initialize workbook using Set command and use the same in the code

Did you build this code or are you trying to maintain an existing code

Dim wb As Workbook
Dim ws As Worksheet
 Dim FilePath As String
 FilePath = "C:\Path\abc.xlsx"

  Set wb = Workbooks(FilePath)
  Set ws = Sheets("Sheet1")