InputBox

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Hi All,

now I open file like this:
Code:
 Dim folder As String
 folder = InputBox("Location of the 'MixMax_Deleted' file :")
  DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Deleted", folder & "\Deleted.xls", True

Works ok.
It's possibility to do it somethig like in excel vb:
Code:
    Set wksDest = Worksheets("Sheet1")
 
    MsgBox "Open file with source data"
    strFile = Application.GetOpenFilename( _
        FileFilter:="Excel Files (*.xls), *.xls)", _
        Title:="Select a File", _
        MultiSelect:=False)
 
 
    If strFile = "False" Then
        Exit Sub
    End If
?

Please help me. Any advice welcome.

regards,
PvK
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I found one solution but I get error and I don't know what means (and why it is in code? why it's necessary?) second line:

Code:
Dim sFile As String, sFilter As String
WizHook.Key = 51488399
WizHook.GetFileName 0, "", "", "", _
    sFile, "", 0, 0, 0, 0, True
 
  DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Deleted", WizHook, True

Error:
Run-time error '2498';
An expression you entered is the wrong data type for one of the arguments
 
Upvote 0
little change:

Code:
  Dim sFile As String, sFilter As String
    
  WizHook.Key = 51488399
  sFilter = "All Files (*.*)"
  WizHook.GetFileName 0, "", "", "", sFile, "", sFilter, 0, 0, 0, True
  
  zmienna_file_name = sFile
  Open zmienna_file_name For Input As #1
  
  
  DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Deleted", sFile, True

Works good!

But, when I run query which delete all records from table and one again want to run this macro (to add new data), I have error than file is already open.
How to close file? (stop streaming?)
regards,
PvK
 
Upvote 0
full code,
work great:

Code:
  Dim sFile As String, sFilter As String
    
  WizHook.Key = 51488399
  sFilter = "Wszystkie pliki (*.*)"
  WizHook.GetFileName 0, "", "", "", sFile, "", sFilter, 0, 0, 0, True
  
  zmienna_file_name = sFile
  Open zmienna_file_name For Input As #1
  
  
  DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Deleted", sFile, True
  
  Close #1
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,681
Members
452,937
Latest member
Bhg1984

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