Solved

FileDiag on Excel 2007 VBA and VB.net

Posted on 2014-07-22
11
583 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

856 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