Solved

VBA Excel - Importing file type frx

Posted on 2010-09-01
5
3,047 Views
Last Modified: 2012-05-10
Hi,

I have an import function that allows me to import modules and forms into another workbook, successfully.  However, I also have .frx files that it does not import.  I dont know what .frx files are.  Can anyone help me allow these files to be imported?  See my code below:
Sub ImportModules()
    Application.ScreenUpdating = False
    Dim Filt As String, Title As String, FilterIndex As Integer, i As Integer, FileName
    Dim blnTest As Boolean
    Dim FSO As Object, Folder As Object, File As Object
    Dim OzMainXLS As Workbook
     
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set Folder = FSO.GetFolder("C:\")
     
    For Each File In Folder.Files
        If UCase(File.Name) = "oz_main.xls" Then
            If WorkbookIsOpen(File.Name) Then
                Set OzMainXLS = Application.Workbooks(File.Name)
            Else
                Set OzMainXLS = Application.Workbooks.Open(File.Path)
            End If
            blnTest = True
            Exit For
        End If
    Next
     
    If blnTest = True Then
        If MsgBox("oz_main.xls already exists." & vbCrLf & vbCrLf & _
        "Would you like to add modules to it?", vbYesNo, _
        "oz_main.xls Exists") = vbNo Then GoTo ExitHere
    End If
     
    If blnTest = False Then
        Set OzMainXLS = Application.Workbooks.Add
        OzMainXLS.SaveAs ("C:\oz_main.xls")
        Windows("oz_main.xls").Visible = True
         
        If MsgBox("oz_main.xls created." & vbCrLf & vbCrLf & "Would you like to import modules?", _
        vbYesNo, "oz_main.xls Created") = vbNo Then GoTo ExitHere
    End If
     
    Filt = "All Files (*.*),*.*," & _
    "Basic Files (*.bas),*.bas," & _
    "Form Files (*.frm),*.frm,"

    FilterIndex = 5
    Title = "Select a File to Import"
    FileName = Application.GetOpenFilename(FileFilter:=Filt, FilterIndex:=FilterIndex, _
    Title:=Title, MultiSelect:=True)
     
    If TypeName(FileName) = "Boolean" Then GoTo ExitHere

    For i = LBound(FileName) To UBound(FileName)
        OzMainXLS.VBProject.VBComponents.Import (FileName(i))
    Next
     
ExitHere:
    OzMainXLS.Save
    Set OzMainXLS = Nothing
    Set FSO = Nothing
    Set Folder = Nothing
    Set File = Nothing
    Application.ScreenUpdating = True
End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
     'Returns TRUE if the workbook is open
    Dim wb As Workbook
    On Error Resume Next
    Set wb = Application.Workbooks(wbName)
    If Err = 0 Then WorkbookIsOpen = True Else WorkbookIsOpen = False
End Function

Open in new window

0
Comment
Question by:NerishaB
[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
  • 3
  • 2
5 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33574237
You don't import FRX files - they are already handled when you import the form.http://www.xcelfiles.com/FRX.htmlWayne
0
 

Author Comment

by:NerishaB
ID: 33574267
Thanks Wayne.
In my code, you see the filter allowing "All files", ".Bas Files" and "Form Files".  Is there a way to filter it such that the user odes not see the 'frx files" when they select All and import?  At the moment, if I just select all files, the .frx files get selected as well and the import stops becasue it does not recgonise .frx.  How can I work arouns this problem?
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33574310
Not when they select "All Files", but you can specify *all* VBA files. Change the filter to this....

    Filt = "All Files (*.*),*.*," & _
    "Visual Basic Files (*.bas; *.frm; *.cls),*.bas;*.frm;*.cls"

Wayne
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 33574336
If you still want to specify which type of VBA file, use this....

    Filt = "All Files (*.*),*.*," & _
    "Form Files(*.frm),*frm," & _
    "Module Files (*.bas),*.bas," & _
    "Class Files (*.cls),*.cls," & _
    "Visual Basic Files (*.bas; *.frm; *.cls),*.bas;*.frm;*.cls"

Wayne
0
 

Author Closing Comment

by:NerishaB
ID: 33574359
Thank you, both solutions work well.
0

Featured Post

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!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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 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.

691 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