VBA Newbie就开放文件对话寻求建议 [英] VBA Newbie seeks advice on open file dialogue

查看:120
本文介绍了VBA Newbie就开放文件对话寻求建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码来选择批量插入SQL的文件。

I'm trying to use the folllowing code to select files for bulk insert into SQL.

Dim fDialog As Office.FileDialog

Dim varFile As Variant

'清除列表框内容。 '¥
''Me.FileList.RowSource =""

'设置文件对话框。 '

设置fDialog = Application.FileDialog(msoFileDialogFilePicker)

使用fDialog

'允许用户在对话框中进行多项选择'

.AllowMultiSelect = True

'设置对话框的标题。 '
$
。标题="请选择一个或多个文件"

'清除当前过滤器,并添加我们自己的过滤器。'¥b $ b .Filters.Clear

.Filters.Add" CSM Files"," * .TXT"

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 "CSM Files", "*.TXT"

'显示对话框。如果.Show方法返回True,则显示'       '用户选择了至少一个文件。如果.Show方法返回'       '错,用户点击了取消。 '

如果.Show = True那么           '循环选择每个文件并将其添加到我们的列表框中。 '¥
For Each varFile In .SelectedItems

'Me.FileList.AddItem varFile

Next zh |
Else

MsgBox"您在文件对话框中单击了取消。"
$
结束如果

结束

' 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



理想情况下,我希望能够获取所选文件的路径,并将其作为参数传递给SQL Server中的批量插入存储过程


Ideally I'd like to be able to take the path of the selected files, and pass it to the Bulk insert Stored procedure in SQL Server
as a parameter.

作为替代方案,我一直试图找到一种方法将所选文件复制到C:\ _Rawdata,当打开
文件对话框时单击。

As an alternative I've been trying to find a way to copy the selected files to C:\Rawdata when the open button on the
file dialogue is clicked.

当前的解决方法是在打开的文件对话窗口中复制和粘贴文件。非常难看。

The current work around is to copy and paste files in the open file dialogue window. Pretty ugly.

任何建议都非常赞赏。

推荐答案

让我指出你的正确您的问题的论坛。

Let me point you to the correct forum for your question.

VBA和Visual Basic .NET(本论坛的主题)是独立且无关的语言。

VBA and Visual Basic .NET (the topic of this forum) are separate and unrelated languages.

有一个论坛致力于VBA:

There is a forum dedicated to VBA here:

http:// social。 msdn.microsoft.com/Forums/en-US/isvvba/threads

 


这篇关于VBA Newbie就开放文件对话寻求建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆