I am relatively new to programming but I will try to explain my issue as best as I can.
I have multiple VBA modules saved in the personal Excel workbook that copy a sheet from a workbook saved on a server and paste it into the active workbook (saved on same server) when pressing assigned buttons on the ribbon.
This works perfectly until I try to 'saveas' to a different location on the same server. Then when hitting the ribbon buttons I get a"permission denied" error message and a .tmp is created in the location I am trying to save to.
I have attached the code below. Sorry if the formatting is off.
Any help would be much appreciated
Blockquote
Public Sub TEST()
Dim sourceBook As Workbook
Application.ScreenUpdating = False
Set targetBook = ActiveWorkbook
Set sourceBook = Workbooks.Open("\\serv01\company\TEST\TEST.xlsx")
sourceBook.Sheets("TEST").Copy Before:=targetBook.Sheets(targetBook.Sheets.Count - 1)
sourceBook.Close
Application.ScreenUpdating = True
Sheets(targetBook.Sheets.Count - 2).Select
Range("A6:A10").Select
Selection.insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1:A5").Select
Selection.Delete Shift:=xlUp
Range("A1:A5").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Sheets(targetBook.Sheets.Count).Select
Range("A1:F5").Select
Selection.Copy
Sheets(targetBook.Sheets.Count - 2).Select
Range("A1:F5").Select
ActiveSheet.Paste
Range("C3").Value = "TEST"
SendKeys "{ESC}"
Range("A6").Select
End Sub