1

I've got a strange situation, and hopefully someone can shed some light on it. In my company, we're working with a Citrix VDI environment, meaning every user has identical software. For some reason on an Excel Workbook, a macro fails at 1 person, while it does work for all others who use this workbook (~10 users). He is new, so his user profile can't be corrupted already and his profile has also been reset afterwards.

After investigation, the code fails on a Workbooks.Open line. But when I debug the code, stepping through each line, the code does work. So there's no error in the data, it's all there.

Finally I figured out, that the issue was caused by the line above this line. I copy a range, then open another workbook and then paste that range there. If I do it the other way around, so first open the other workbook, switch back to the original workbook and then copy the range, the code works (see below).

How can it be, that this works for everybody but one? Especially since everybody has the same software/rights.

Old code:

Range("Input").Copy

Dim oNewFile As Workbook
Set oNewFile = Application.Workbooks.Open(sNewFile, , True)

oNewFile.Activate
Sheets("Input").Range("A4").PasteSpecial Paste:=xlPasteValues

New code:

Dim oNewFile As Workbook
Set oNewFile = Application.Workbooks.Open(sNewFile , , True)

ThisWorkbook.Activate

Range("Input").Copy

oNewFile.Activate
Sheets("Input").Range("A4").PasteSpecial Paste:=xlPasteValues

EDIT: The error message is this:

enter image description here

Majjek
  • 41
  • 3
  • **What are the error messages**? – user18521918 Jun 20 '22 at 05:57
  • Not directly relevant to your question but you should read on [how to avoid using Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba?rq=1), using select/activate is a very bad practice and it is also prone to error. – Raymond Wu Jun 20 '22 at 06:05
  • You shouldn't use implcit references ... better use `ThisWorkbook.Range("Input").copy` – Ike Jun 20 '22 at 10:55
  • Thanks for the advice, I will try to make this a common practice. I wasn't able to test this though. But it's still strange that it only fails for 1 person. – Majjek Jun 21 '22 at 07:58

0 Answers0