VBA Site contains VBA code to create macros in WORD EXCEL ACCESS OUTLOOK

 

MsoFileDialogType

 

Name

Value

Description

msoFileDialogFilePicker

3

File picker dialog box.

msoFileDialogFolderPicker

4

Folder picker dialog box.

msoFileDialogOpen

1

Open dialog box.

msoFileDialogSaveAs

2

Save As dialog box.

Table from https://msdn.microsoft.com/en-us/library/office/ff865284.aspx

 

Option Explicit


Sub msofile()

Dim intChoice As Boolean

Dim Name1 As String

Dim Name2 As String

Dim Directory As String

Dim i As Integer

Dim strpath As String

Dim x As String

Dim choice As Boolean

Dim strpath1 As String

 

Name1 = Application.UserName ' pick the one you need

Name2 = Environ("UserName")

Directory = "C:\Users\" & Name2 & "\Documents\VBA CODE\"

Call Application.FileDialog(3).Filters.Clear

Call Application.FileDialog(3).Filters.add("Text Files Only", "*.txt") ' or "Text/CSV files", "*.txt;*.csv" or "All files", "*.*"

Application.FileDialog(3).InitialFileName = Directory

Application.FileDialog(3).AllowMultiSelect = True

intChoice = Application.FileDialog(3).Show

If intChoice <> 0 Then

For i = 1 To Application.FileDialog(3).SelectedItems.Count

strpath = Application.FileDialog(3).SelectedItems(i)

x = "C:\WINDOWS\notepad.exe" & " " & strpath

Dim RetVal

RetVal = Shell(x, 1)

Call Shell("TaskKill /F /PID " & CStr(RetVal), vbHide)

Open strpath For Append As #1

Dim add

add = InputBox("Write something")

Print #1, add

Close #1

RetVal = Shell(x, 1)

Call Shell("TaskKill /F /PID " & CStr(RetVal), vbHide)

Application.FileDialog(2).InitialFileName = strpath

choice = Application.FileDialog(2).Show

strpath1 = Application.FileDialog(2).SelectedItems(i)

If choice <> 0 Then

FileCopy strpath, strpath1 ' Copy source to target.

Else

End If

Next

End If

End Sub

 

MsoFileDialogType - File picker

 

Sub show_selected_items()

Dim ob As Object, files As Object, file As Object

Dim FolderName As String

With Application.FileDialog(msoFileDialogFilePicker)

.AllowMultiSelect = True

.Show

For i = 1 To .SelectedItems.Count

MsgBox .SelectedItems(i)

Next i

End With

End Sub



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl