![]() ![]() The only thing I didn't know was if wb2 would always have a sheet name equal to ShtName but I'm guessing it will since it's inside your if err.number = 0 Now the copy code only runs if isWS = true, and it will always be true unless an error 9 code is thrown. I also made sure all your Range(), Cells(), and Columns() were referencing the correct sheet (just incase excel is getting confused) and I assumed the active sheet was the correct sheet, but you may want to verify this in the code to make sure it's doing the correct thing in the correct sheet. The big thing I did was split off your error handling, this way it only resumes next when you don't find the sheet in wb1 and all other errors (none error 9 errors) will still show your error message. MsgBox "Error: " & Err.Number & vbNewLine & Err.Description Ws2.Range("BA2:BC2").AutoFill Destination:=ws2.Range(ws2.Cells(2, "BA"), ws2.Cells(lastrow, "BC")), Type:=xlFillDefault Lastrow = ws2.Cells(, "BE").End(xlUp).Row Ws2.Columns("BE:BV").PasteSpecial xlPasteValues Its kind of a shot in the dark, but I tried cleaning up your code a little bit. Print Preview still fails with those removed and just doing the copy and paste from the previous sheet. I've tried commenting out "On Error Resume Next", "On Error Goto 0", "If.", "End If", and "DoEvents". Selection.AutoFill Destination:=Range(Cells(2, "BA"), Cells(lastrow, "BC")), Type:=xlFillDefault Lastrow = Cells(Rows.Count, "BE").End(xlUp).Row Set wb1 = Workbooks.Open(FileName)įor i = LBound(sArray) To UBound(sArray) 'Loops through array, copies available data from last report I would like to have this code function in some way as it's still needed. If I skip this section then it works as intended. This is the code that causes print preview to fail to load in some way. Is this just a bug or possibly something in the code? I have not had this issue with any other documents that run VBA. The only thing related to printing that the VBA does is change the print area. Closing Excel and reopening the document restores print preview to normal functionality. Almost every time after running all the VBA and then trying to print, print preview gets stuck either finding the printer or loading page sizes as seen in the picture. It opens other workbooks, copies data from them, closes them and then loops through the data several times to generate reports that we print and use. ![]() I have an Excel workbook in which almost everything is automated. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |