Beneindias
Board Regular
- Joined
- Jun 21, 2022
- Messages
- 120
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi guys,
I have a file to calculate diesel consumption per month, and I have a VBA code where I start a new month by inputing the number of the new month in an inputbox, then, it deletes values from the table, adds month name in a cell, and saves file with new month in the end of the name.
Problem is, this code is saving the file to "Documents" folder, but I want it to save the file to the same folder (this folder needs to be dynamic, because this file is used by more than one person).
Already tried a bunch of solutions that I found online, but I cant make it work as I want, and it always save to Documents, or the path needs to be hardcoded.
Can anibody help me with this?
I have a file to calculate diesel consumption per month, and I have a VBA code where I start a new month by inputing the number of the new month in an inputbox, then, it deletes values from the table, adds month name in a cell, and saves file with new month in the end of the name.
Problem is, this code is saving the file to "Documents" folder, but I want it to save the file to the same folder (this folder needs to be dynamic, because this file is used by more than one person).
Already tried a bunch of solutions that I found online, but I cant make it work as I want, and it always save to Documents, or the path needs to be hardcoded.
Can anibody help me with this?
VBA Code:
Public Sub MyInputBox()
Dim MyInput As String
Dim NumericInput As Boolean
Dim MyInputText As String
Dim new_Workbook_Name As Variant
'Set workbook_Name = "Abastecimentos Prio - " & MyInputText
'Caixa para input do user quando se carrega no botão
MyInput = InputBox("Escrever número do novo mês", "Iniciar novo mês", "Número do novo mês")
NumericInput = IsNumeric(MyInput)
'Pega no que foi inserido e checa se é número e se está entre 1 e 12
If NumericInput Then
If MyInput >= 1 And MyInput <= 12 Then
MyInputText = StrConv(MonthName(MyInput, False), vbProperCase)
Call ResetTable
Range("C3").Value = MyInputText
ActiveWorkbook.SaveAs Filename:="Abastecimentos Prio - " & MyInputText
Else
'GoTo errHand
MsgBox "Número de mês mal introduzido"
End If
Else
'GoTo errHand
MsgBox "Tem que introduzir número do mês"
End If
Exit Sub
End Sub