optionsactuelles
New Member
- Joined
- Sep 22, 2017
- Messages
- 2
My coworker has built the code and I'm only trying to save it to a specific site, this is the code:
After the Set LockBook there it continues. What I added was the With Application.FileDialog part.
Everything works, it saves on the computer itself and it saves onto the link I want it to save. However, after it saves, I get the error '9' and when I go on "debug" it highlights the line
How do I fix this??
Code:
Public Sub SaveAs_TL_ETI_Y()
Dim NewBook As Workbook
Dim varResult As Variant
Dim E_F, E_SN, P_PN, P_SN, D_F As Variant
Dim FName As Variant
Dim LockBook As Workbook
'Saves TL_ETI_Y as new workbook
E_F = ThisWorkbook.Sheets("TL_ETI_Y").Range("F16").Value
E_SN = ThisWorkbook.Sheets("TL_ETI_Y").Range("C13").Value
P_PN = ThisWorkbook.Sheets("TL_ETI_Y").Range("B14").Value
P_SN = ThisWorkbook.Sheets("TL_ETI_Y").Range("F14").Value
D_F = ThisWorkbook.Sheets("TL_ETI_Y").Range("B21").Value
'Sets new workbook name to pre-specified name
FName = E_F & " - " & E_SN & " - " & P_PN & " - " & P_SN & " - " & D_F
varResult = Application.GetSaveAsFilename(InitialFileName:=FName, FileFilter:="Excel Workbook (*.xlsx), *.xlsx")
'Creates new workbook with the above mentioned name
Set NewBook = Workbooks.Add
ThisWorkbook.Sheets("TL_ETI_Y").Copy Before:=NewBook.Sheets(1)
NewBook.SaveAs FileName:=varResult
With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False
.InitialFileName = "(mydirectory)"
If .Show = -1 Then .Execute
End With
'Locks all "question" cells to prevent editing
Set LockBook = Workbooks(FName & ".xlsx")
LockBook.Sheets("TL_ETI_Y").Cells.Locked = False
LockBook.Sheets("TL_ETI_Y").Range("A1:J1").Locked = True
LockBook.Sheets("TL_ETI_Y").Range("A2:B10").Locked = True
LockBook.Sheets("TL_ETI_Y").Range("C2:J3").Locked = True
LockBook.Sheets("TL_ETI_Y").Range("C4:D6").Locked = True
After the Set LockBook there it continues. What I added was the With Application.FileDialog part.
Everything works, it saves on the computer itself and it saves onto the link I want it to save. However, after it saves, I get the error '9' and when I go on "debug" it highlights the line
Code:
Set LockBook = Workbooks(FName & ".xlsx")
How do I fix this??