SaveAs file to the same folder

Beneindias

Board Regular
Joined
Jun 21, 2022
Messages
97
Office Version
  1. 365
Platform
  1. Windows
  2. 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?

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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Change this line:
VBA Code:
ActiveWorkbook.SaveAs Filename:="Abastecimentos Prio - " & MyInputText
to this:
VBA Code:
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\Abastecimentos Prio - " & MyInputText
 
Upvote 0
Solution
Change this line:
VBA Code:
ActiveWorkbook.SaveAs Filename:="Abastecimentos Prio - " & MyInputText
to this:
VBA Code:
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\Abastecimentos Prio - " & MyInputText
Yeap, thats it.

Thank you
 
Upvote 0

Forum statistics

Threads
1,215,123
Messages
6,123,183
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top