Ask user where to store file one time

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I am wanting to ask the user where they would want to store a file, but I only want to ask this question one time, and this would be when they first use this program. Any help would be greatly appreciated. I thought about using a time and date stamp and store it in a variable. So, each time the user opens this form, the vba code will check to see if there is a value in that variable and if so, don't ask that question, otherwise ask where they want to store this file. Is this a good approach or is there a better and hopefully not to complicated way. Thank you.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Maybe
VBA Code:
...
If GetSetting("MyApp", "Startup", "AlreadyUsed") <> "Yes" Then
'   your file-saving section
    If '***saving operation is successful***' Then
        SaveSetting "MyApp", "Startup", "AlreadyUsed", "Yes"
    End If
End If
...
 
Upvote 0
Storing something in a variable only lasts until the VBA project has been reset. Creating a very hidden sheet and and putting in either a named range or just cell A1 is more permanent

You could also have a table that saves each user's response.
Environ("UserName") gets the user's Login ID


VBA Code:
Sub AskUSerForPathName()
  Debug.Print GetSaveLocation
End Sub

VBA Code:
Function GetSaveLocation() As String
  Dim v As Variant
  Dim Fltr As String
  Dim PathName As String
  Dim Cel As Range
  Dim Rng As Range
  Dim UID As String
  
  UID = Environ("UserName")
  Set Cel = Sheets("Hidden").Range("UserChoice").Resize(1, 1).Offset(1, 0)
  Set Rng = Sheets("Hidden").Range(Cel, Cel.Offset(1000000, 0).End(xlUp))
  For Each Cel In Rng
    If Cel.Value = UID Then
      PathName = Cel.Offset(0, 1).Value
      Exit For
    End If
  Next Cel
  
  If PathName <> "" Then
    GetSaveLocation = PathName
    Exit Function
  End If
  
  
  Fltr = "Excel Files (*.xlsx;*.xlsm), *.xlsx;*.xlsm"
  v = Application.GetSaveAsFilename(, Fltr, 1, "Choose location and filename")
  If v <> False Then
    PathName = v
    Set Cel = Sheets("Hidden").Range("UserChoice").Resize(1, 1).Offset(1000000, 0).End(xlUp).Offset(1, 0)
    Cel.Value = UID
    Cel.Offset(0, 1).Value = PathName
    GetSaveLocation = PathName
  End If
    
  
End Function

Book3
EF
1User IDPathFile
2x12477C:\Users\x12477\OneDrive - ALLWK\Documents\Book3.xlsx
Hidden
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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