Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FileDiag on Excel 2007 VBA and VB.net

Posted on 2014-07-22
11
Medium Priority
?
593 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 1600 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Independent Software Vendors: 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!

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

721 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