Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Excel File Dialog:

 

The following Excel macro code in vba creates a file dialog for an Excel file.

Several files can be selected and adopted as text.

 

Download: The code template is available for download under Codedocu.de as Excel sample file.

or: The vba code sample can be copied as vba code below.

 

 

In the file dialog

By clicking on the button: -> Select Files

 

 

Vba code to paste into the Excel file

 

'*Reference Microsoft scripting Runtime    http://www.microsoft-programmierer.de/Details?d=1076

Public Sub Select_File()

    '-----------< Select_File() >-----------

 

    '------< Select_File() >------

    '--< File-Dialog >--

    Dim objFiledialog As FileDialog

    Set objFiledialog = Application.FileDialog(msoFileDialogFilePicker)

    objFiledialog.AllowMultiSelect = True

    objFiledialog.ButtonName = "->Select Files"

    objFiledialog.Filters.Add "Add Files""*.*"

    objFiledialog.Title = "Select Files.."

    objFiledialog.InitialView = msoFileDialogViewTiles

    objFiledialog.InitialFileName = ActiveWorkbook.Path

    objFiledialog.AllowMultiSelect = True

    If Not objFiledialog.Show() = True Then

        Exit Sub

    End If

    '--< File-Dialog >--

 

    '-< check >-

    '</ Ordner ist leer >

    If objFiledialog.SelectedItems().Count = 0 Then

        Exit Sub

    End If

    '</ Ordner ist leer >

    '-</ check >-

 

    Dim sFilename As String

    Dim sFiles As String

    sFiles = ""

    '----< @Loop: Files >----

    Dim iFile As Integer

    For iFile = 1 To objFiledialog.SelectedItems.Count

        '------< Loop.Item  >------

        DoEvents

 

        '< get selection >

        sFilename = objFiledialog.SelectedItems(iFile)

        '</ get selection >

 

        '< correct >

        sFilename = Replace(sFilename, ActiveWorkbook.Path & "\""", 1, 1, vbBinaryCompare)

        '</ correct >

 

 

        '< add >

        sFiles = sFiles & ";" & sFilename

        '</ add >

    Next

    '----</ @Loop: Files >----

    '< correct >

    sFiles = Replace(sFiles, ";""", 1, 1, vbBinaryCompare)

    '</ correct >

 

 

    '< write_into_cell >

    ActiveWorkbook.Names("varFiles").RefersToRange.Value2 = sFiles

    '</ write_into_cell >

    '-----------</ Select_File() >-----------

End Sub

 

 

 

 

 

Mobile
»
Installation of .NET Core 2.1 on a web server
»
Set upload of very large files in Asp.Net MVC Core 2.
»
Error: Identity column can not be updated, IDENTITY_INSERT is set to OFF
»
Asp Error: IDENTITY_INSERT OFF when accessing AspNetUsers registry
»
ASP IIS Error: 440.13 Not Found. upload file size is exceeded
»
InvalidOperationException: An exception occurred while reading a database value for property
»
A database operation failed while processing the request. SqlException: Invalid object name
»
InvalidOperationException: No database provider has been configured for this dbContext
»
NullReferenceException: Object reference not set to an instance of an object.
»
InvalidOperationException: The expected type was System.Boolean but the actual value was null.

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de