How to Save File Inside Folder(Variable Name) Excel VBA?

Asked

Viewed 9 times

0

am having trouble saving workbook in created directory

Code to create folder

Sub CRIARPASTA()

Dim VAR As Object, NOVAPASTA
Dim Nome As String
Dim OS As String

Nome = Worksheets(3).Range("f5").Value
OS = Worksheets(3).Range("G2").Value

Set Pastas = CreateObject("Scripting.FileSystemObject")
Set Pasta = Pastas.CreateFolder("C:\Users\DiskTech\Desktop\disk\O.S\" & OS & "-" & Nome)

NOVAPASTA = CAMINHO & “NOVAPASTA”
End Sub

code to save file

'Cria esta nova aba
Set NovoWB = Workbooks.Add(xlWBATWorksheet)
With NovoWB
'Copia a aba atual para o novo arquivo, como a segunda aba
ThisWorkbook.ActiveSheet.Copy After:=.Worksheets(.Worksheets.Count)
'Deleta a primeira aba do arquivo criado (Aba em branco)
.Worksheets(1).Delete
'Troque "Novo Arquivo" para um outro nome qualquer que preferir

Activeworkbook.Saveas Filename:="C: Users Disktech Desktop disk O.S O.S-" & Name & ". xlsx"

'Fecha o novo arquivo
.Close False
End With

'Permite que o Excel volte a atualizar a tela
Application.ScreenUpdating = False
'Permite que o Excel volte a exibir alertas
Application.DisplayAlerts = False
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.