将以下vba代码更改为特定格式。 [英] Change the following vba code to a specific format.

查看:65
本文介绍了将以下vba代码更改为特定格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...............

Hi every one...............

我有vba代码,会列出文件名和标题特定目录中的pdf文件。

I have vba code which will list out the filename and the title of the pdf files in a specific directory.

现在我想要一个小小的改动。所以如果我点击一个按钮说[Bowse]它必须检索文件夹并显示路径文件夹中的文件夹(c:/ abc / qwerty /)。

Now i want a small change in it.So if I click a button say [Bowse] it has to retreive the folder and display the path of the folder (c:/abc/qwerty/) in a text box.

然后,如果我单击按钮[提交],它必须执行从中获取文件名和标题的功能文本框中提到的路径中的文件夹。

Then if i click a button [submit] it has to do the functionality of getting the file name and titles from the folder in the path mentioned in the text box.

你能帮我解决这个问题吗?

Can you help me with this?

Veeru

推荐答案

以下是一些示例代码。运行子 

Here is some example code to start from. Run the sub 

ExampleUse

ExampleUse

了解如何使用它。

选项明确

键入BROWSEINFO

    hOwner As Long

    pidlRoot As Long

    pszDisplayName As String

    lpszTitle As String

    ulFlags As Long

    lpfn As Long

    lParam As Long

    iImage As Long

结束类型

Type BROWSEINFO
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type

声明函数SHGetPathFromIDList Lib" shell32.dll" _
$
   别名"SHGetPathFromIDListA" (ByVal pidl As Long,ByVal pszPath As String)As long

Declare Function SHGetPathFromIDList Lib "shell32.dll" _
    Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

声明函数SHBrowseForFolder Lib" shell32.dll" _
$
   别名"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO)As Long

Declare Function SHBrowseForFolder Lib "shell32.dll" _
    Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

声明函数FindWindow Lib" user32"别名"FindWindowA" _

 (ByVal lpClassName As String,ByVal lpWindowName As String)As Long

Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
 (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Sub ExampleUse()

FindAllFilesInFolder" PDF" b
End Sub

Sub ExampleUse()
FindAllFilesInFolder "PDF"
End Sub

Sub FindAllFilesInFolder(ext as String)

Dim Msg As String

Dim SelectedDir As String

Dim WorkFile As String

Msg ="选择带有"<"的文件夹&安培;分机和"文件。"
$
SelectedDir = GetDirectory(Msg)

MsgBox"目录是" &安培; SelectedDir

WorkFile = Dir(SelectedDir&" \ *。"& ext)

Do WorkFile<> "" b $ b   MsgBox SelectedDir& " \" &安培; WorkFile

   WorkFile = Dir()

循环

结束子   '来自这里,或来自其他用户形式

Sub FindAllFilesInFolder(ext As String)
Dim Msg As String
Dim SelectedDir As String
Dim WorkFile As String
Msg = "Select the folder with the " & ext & " files."
SelectedDir = GetDirectory(Msg)
MsgBox "The directory is " & SelectedDir
WorkFile = Dir(SelectedDir & "\*." & ext)
Do While WorkFile <> ""
   MsgBox SelectedDir & "\" & WorkFile
   WorkFile = Dir()
Loop
End Sub   'works from either here, or from another userform

函数GetDirectory(Msg)As String

Dim bInfo As BROWSEINFO

Dim path作为字符串

Dim x As Long

Function GetDirectory(Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim x As Long

bInfo.pidlRoot = 0&        "&NBSP;&NBSP; Root folder = Desktop

bInfo.lpszTitle = Msg

bInfo.ulFlags =& H1        "&NBSP;&NBSP;要返回的目录类型

bInfo.pidlRoot = 0&        '   Root folder = Desktop
bInfo.lpszTitle = Msg
bInfo.ulFlags = &H1        '   Type of directory to return

'  显示对话框

x = SHBrowseForFolder(bInfo)

'   Display the dialog
x = SHBrowseForFolder(bInfo)

'  解析结果

path =空格

'   Parse the result
path = Space


(512)

如果是SHGetPathFromIDList(ByVal x,ByVal路径)那么

   GetDirectory = Left(路径,InStr(路径,Chr
(512)
If SHGetPathFromIDList(ByVal x, ByVal path) Then
   GetDirectory = Left(path, InStr(path, Chr


(0)) - 1)

Else:GetDirectory =""

结束如果

结束功能

(0)) - 1)
Else: GetDirectory = ""
End If
End Function


这篇关于将以下vba代码更改为特定格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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