Solved

FileDiag on Excel 2007 VBA and VB.net

Posted on 2014-07-22
11
590 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 31

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 31

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Author Comment

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

Why you delete code from msoFileDialogFilePicker ?
0
 
LVL 31

Expert Comment

by:gowflow
ID: 40211310
Sorry ?
0
 
LVL 13

Author Comment

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

Expert Comment

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

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

623 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