cope method of worksheet class failed error - working code suddenly stopped working...

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Any has an idea why this occurs?
VBA Code:
Private Sub bezb_Click()
Dim narzutr As String
Dim narzutm As String
Dim wName As String
Dim pName As String
Dim cell As Range
Dim fname As String, wb As Workbook, project As String
narzutr = 1.15
pName = Range("C3").Value
wName = "Faktury" + Left(pName, 5)
fname = Application.GetOpenFilename("Excel Files (*.xl*), *.xl*")
Set wb = Workbooks.Open(fname)
    For Each sh In wb.Sheets
        If Application.CountA(sh.Cells) > 0 Then
            sh.Copy After:=ThisWorkbook.Sheets(Sheets.Count)
         End If
    Exit For
    Next
    Application.DisplayAlerts = False
        wb.Close True
    Application.DisplayAlerts = True
1668667116343.png
1668667145170.png
 
this worked for me

VBA Code:
  Dim sh As Worksheet
    Set wb = ActiveWorkbook
    For Each sh In wb.Worksheets
        If sh.Name = "Wycena z dokladnymi materialami" Then
            sh.Visible = xlSheetVisible
            sh.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count): Exit For
         End If
    Next sh

try copying all above & see if resolves your issue

Dave
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top