Possible to set a variable value with sendkeys?

misterpox

New Member
Joined
Jan 7, 2003
Messages
26
Is it possible to assign to a variable's value, the file that a user selects from within the dialogue window that opens from a SendKeys command?

For example, the following is the procedure linked to a command button on a form;

Private Sub Command15_Click()
AppActivate "Microsoft Access"
SendKeys ("^o"), True
End Sub

When the open file window opens and a user browses and selects a file, can that file path and name be assigned somehow to a string variable within a procedure? I'm trying to create a way for a user to specify an Excel file they want to import, by allowing them to browse to the file and select it.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
With access2002 or more recent, try something like this to get the file name:

Code:
Private Sub OpenFileDialog()

'Requires reference to Microsoft Office 10.0 Object Library.

Dim fDialog As Office.FileDialog
Dim varFile As Variant

'Clear listbox contents.
'Me.FileList.RowSource = ""

'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
  'Allow user to make multiple selections in dialog box
  .AllowMultiSelect = True

  'Set the title of the dialog box.
  .Title = "Please select one or more files"

  'Clear out the current filters, and add our own.
  .Filters.Clear
  .Filters.Add "Access Databases", "*.MDB"
  .Filters.Add "Access Projects", "*.ADP"
  .Filters.Add "All Files", "*.*"

  'Show the dialog box. If the .Show method returns True, the
  'user picked at least one file. If the .Show method returns
  'False, the user clicked Cancel.
  If .Show = True Then
  'Loop through each file selected and add it to our list box.
    For Each varFile In .SelectedItems
      Me.FileList.AddItem varFile
    Next
  Else
    MsgBox "You clicked Cancel in the file dialog box."
  End If
End With
End Sub

This is how to do it with Access2K or earlier

http://www.mvps.org/access/api/api0001.htm

Basically, these are function/API calls that can return a value that you drop into a variable and send via your sendkeys command.

Mike
 
Upvote 0
Mike,

Thank you very much. This is alot more complicated that I thought it would be, but I get the idea. Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

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