Solved

FileDiag on Excel 2007 VBA and VB.net

Posted on 2014-07-22
11
571 Views
Last Modified: 2014-07-22
Dear Experts,
I have three questions

question-1 I am using Excel 2007  VBA to do marco  as follows for open FIle Diaglog box
and set the file path at C:\temp\*.* but it just open the file Diag and *.* is
put at the file inputbox,but I can Not see all file from *.*, Why?

Question-2 What it is different the program  filediag code for VBA and VB.NET or Same or
Just smal change ? Could you provide it ?

Question-3  How could I change directory on FileDiag  and if using .InitialFileName, it will
show the last slash string in the filename box around bottom of FileDiag box. Why ?
Duncan


Sub FileDiag()

    Dim strFileSelected As String
    Dim objOfficeDialog As Object
    Dim wbDestination As Workbook
    Dim wbSource As Workbook
    Dim sh As Worksheet
    Dim res As String
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    Set objOfficeDialog = Application.FileDialog(msoFileDialogFilePicker)
    Set wbDestination = ActiveWorkbook
Application.FileDialog(msoFileDialogFolderPicker _
    ).InitialFileName = "C:\Temp\*.*"
  ' res = "Q:\Debt\Inputs\" & Format(Date, "yyyy") & "\" & Format(Date, "yyyy") & Format(DateAdd("m", -1, Date), "mm") & "\Reporting"

   'Debug.Print res
  
    With objOfficeDialog
       ' .Title = "Select the Project Cost Allocation file"
       ' .AllowMultiSelect = False
       '.InitialFileName = res
    .Show
End With
        Application.DisplayAlerts = True
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Exit Sub
End Sub

Open in new window

0
Comment
Question by:duncanb7
  • 5
  • 5
11 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 40211291
for 1)
to see the files

replace in your code this
msoFileDialogFolderPicker

by this
msoFileDialogFilePicker

for 2) not familiar with vb.net

for 3) simply
replace this
"C:\Temp\*.*"

by this
"C:\Temp\"


gowflow
0
 
LVL 13

Author Comment

by:duncanb7
ID: 40211297
what is reply at Q1, and q3 is not working

DUncan
0
 
LVL 29

Accepted Solution

by:
gowflow earned 400 total points
ID: 40211301
Oops I can see your code have too many instructions for nothing use this instead:

Sub FileDiag()

    Dim strFileSelected As String
    Dim objOfficeDialog As Object
    Dim wbDestination As Workbook
    Dim wbSource As Workbook
    Dim sh As Worksheet
    Dim res As String
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    'Set objOfficeDialog = Application.FileDialog(msoFileDialogFilePicker)
    Set wbDestination = ActiveWorkbook

With Application.FileDialog(msoFileDialogFilePicker)
    .InitialFileName = "C:\Temp\"
    .Show
    Application.DisplayAlerts = True
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End With
    
  
    
End Sub

Open in new window


gowflow
0
 
LVL 13

Author Comment

by:duncanb7
ID: 40211307
Q3 is working at your code

Why you delete code from msoFileDialogFilePicker ?
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40211310
Sorry ?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 13

Author Comment

by:duncanb7
ID: 40211311
Sorry for what ?
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40211313
I do not understand your question. What do you need ?
gowflow
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40211315
I need to logoff now will log in back in 1 to 2 hours. Sorry
gowflow
0
 
LVL 13

Author Comment

by:duncanb7
ID: 40211317
How about the final question 2, similar code for VB.NET ? it seems similar or same, RIght ?


Duncan
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 total points
ID: 40211553
1) Use the Filters property of the dialog. See example at below link
http://msdn.microsoft.com/en-us/library/office/aa210589(v=office.11).aspx

2) VB.NET is different.
     Dim fd As New OpenFileDialog
     fd.ShowDialog()

3) Because it wants to :-). That is the property to be used to set the initial path as shown in example on below page
http://msdn.microsoft.com/en-us/library/office/aa210656(v=office.11).aspx
0
 
LVL 13

Author Closing Comment

by:duncanb7
ID: 40211562
Thanks for all your reply

Duncan
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now