Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FileDiag on Excel 2007 VBA and VB.net

Posted on 2014-07-22
11
Medium Priority
?
597 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

927 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