Good afternoon,
I have written (borrowed and amended) some code to open a file off my desktop which works fine.
But as several people have access to the main file and can load a file from their desktop I am having issues making this work.
I have created a cell reference "desktop" that mirrors the location dependant upon who is using the file (amendments are made to the desktop based on username) so that it does look like
this is the location I would normally use Set src = Workbooks.Open("C:\Users\THIS CHANGES\Desktop\file.xlsx", but it fails in the code below saying the file cannot be found.
Whats the best way around this as I could make sure the file is saved in a specific location, but using the desktop is easier.
I have written (borrowed and amended) some code to open a file off my desktop which works fine.
But as several people have access to the main file and can load a file from their desktop I am having issues making this work.
I have created a cell reference "desktop" that mirrors the location dependant upon who is using the file (amendments are made to the desktop based on username) so that it does look like
this is the location I would normally use Set src = Workbooks.Open("C:\Users\THIS CHANGES\Desktop\file.xlsx", but it fails in the code below saying the file cannot be found.
Whats the best way around this as I could make sure the file is saved in a specific location, but using the desktop is easier.
Code:
Sub GrabACWAHTData()
Dim lCopyLastRow As Long, lDestLastRow As Long
Dim desktop As String
desktop = Worksheets("Calcs").Range("A23").Value
Application.ScreenUpdating = False
Sheet2.Visible = True
Set wsCopy = Workbooks("source.xlsm").Worksheets("sheet")
Set wsDest = Workbooks.Open(desktop)
wsDest.Parent.Windows(1).Visible = False
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "P").End(xlUp).Row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
wsCopy.Range("A2", wsCopy.Cells(lCopyLastRow, "A")).Copy
wsDest.Cells(lDestLastRow, "A").PasteSpecial xlValues
Sheet2.Visible = xlVeryHidden
wsDest.Parent.Close True
Sheets("Welcome").Select
Range("E11").Select
Range("E11").Value = Format(Now(), "mm/dd/yyyy hh:mm")
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
[code/]
thanks in advance