VBA word 2010 Common dialog box licence problem

MrDavidThorn
MrDavidThorn used Ask the Experts™
on
Hi Experts

I have designed a macro enabled word document with a form that contains a common dialog box, works fine on my own machine, when the document is opened by other users  - they can not access the common dialog box due to MS licence issues (http://dutchgemini.wordpress.com/2010/12/23/vba-cannot-create-mscomdlg-commondialog-activex/) - I can resolve the problem using the reg fix in the url, however Im unsure of licence restriction and dont want to tempt fate, is there away to get around the common dialog licence problem (doesnt make sense as all users have it install anyhow)  - or can I use an API call for a user to select a file (its an Excel file the user needs to select)


Dim cdExcelFile As Object

Set cdExcelFile = VBA.CreateObject("MSComDlg.CommonDialog")
cdExcelFile.DialogTitle = "Select new source file"

cdExcelFile.Flags = cdlOFNFileMustExist + cdlOFNPathMustExist
cdExcelFile.Filter = "Microsoft Excel Workbooks (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm;"



cdExcelFile.ShowOpen
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Retired
Top Expert 2012
Commented:
I suggest that you use the FileDialog from Office. Here is some sample code :
Sub InsertPics()
    Dim fd As FileDialog
    Dim rng As Range
    Dim ilsh As InlineShape
    
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    Dim strFileName As Variant
    
    With fd
        .Filters.Clear
        .Filters.Add "All files", "*.*"
        .Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
        If .Show Then
            Set rng = Selection.Range
            rng.Collapse wdCollapseEnd
            For Each strFileName In .SelectedItems
                Set ilsh = ActiveDocument.InlineShapes.AddPicture(strFileName, False, True, rng)
                Set rng = ilsh.Range
                rng.Collapse wdCollapseEnd
                rng.Text = vbCr & vbCr
                rng.Collapse wdCollapseEnd
            Next strFileName
        End If
    End With

End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial