I found the following code from the Internet (see below). I have no clue if this could be used together with GetOpenFilename. I wonder if it would be possible to use GetOpenFilename to find the xlsx you want to open, and somehow define files name and full path as FullPathAndFileName and use this code to ope the file.
Maybe someone smarter person could look into this. So far I haven't found anything on the Internet that would allow to use getopenfilename and open xlsx files. If some one can crack this tough nut, I bet there would at least few people who might like this macro.
' Headers/declarations
Option Explicit
Dim ExcelApp As Object
Dim ExcelWorkbook As Object
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const STATUS_PENDING = &H103&
Private Const PROCESS_QUERY_INFORMATION = &H400
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Process entire Excel file and extract plots from charts and worksheets
'
' This can be done from a machine running VB with Excel 2003
' that will read Excel 2007 files (.xlsx).
'
' It uses the Microsoft Moc.exe utility (which is installed when the MS file
' converter is installed) to convert and open up the .xlsx *without* the
' pesky popup.
'
' Use at your own risk.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ProcessExcelFile(sFullPathAndFileName As String)
On Error GoTo ehandler:
Dim ExcelApp As Object
Dim ExcelWorkbook As Object
Dim ICnt As Integer
Dim Start As Single
Dim i As Integer
Dim j As Integer
Dim sType As String
Dim Worksheet_Count As Integer
' PNG, GIF, JPG
sType = "PNG"
Start = Timer
Set ExcelApp = CreateObject("Excel.Application")
' Note in using Excel 2003 files:
' To open workbook *directly* (if you knew the file was an Excel 2003 format)
' instead of using the ShellAndWait
'
' Set ExcelWorkbook = ExcelApp.Workbooks.Open(sFullPathAndFileName)
'
' You would convert things like ExcelApp.Activeworkbook.ActiveSheet.Name to
' ExcelWorkbook.ActiveSheet.Name
'
' You can't seem to use the ShellandWait method, because Excel will open the file, but ShellAndWait will
' only continue *after* the Excel application is shut down!
'
' this opens a workbook (Excel 2007)
Call ShellandWait("C:\Program Files\Microsoft Office\Office12\Moc.exe " & sFullPathAndFileName)
Debug.Print ExcelApp.ActiveWorkbook.Name
ExcelApp.Visible = False
' Begin the loop through all CHARTS in the workbook
For i = 1 To ExcelApp.ActiveWorkbook.Charts.Count
' Select the chart
ExcelApp.ActiveWorkbook.Charts(i).Select
' Debug.Print "--->" & ExcelApp.ActiveWorkbook.ActiveSheet.Name
' Debug.Print "--->" & ExcelApp.ActiveWorkbook.ActiveSheet.ChartObjects.Count
' single chart
' Extract the *entire* chart as a single JPG
ExcelApp.ActiveWorkbook.ActiveChart.Export FileName:=CurDir & "\output\" & _
ExcelApp.ActiveWorkbook.ActiveChart.Name & "." & sType, FilterName:=sType
' Extract individual charts, if they exist
For j = 1 To ExcelApp.ActiveWorkbook.ActiveSheet.ChartObjects.Count
ExcelApp.ActiveWorkbook.ActiveSheet.ChartObjects(j).Chart.Export FileName:=CurDir & "\output\" & _
ExcelApp.ActiveWorkbook.ActiveChart.Name & _
"_plot" & Format(j, "000") & "." & sType, FilterName:=sType
Next j
Next i
' Begin the loop through all WORKSHEETS in the workbook
For i = 1 To ExcelApp.ActiveWorkbook.Worksheets.Count
' Select the chart
ExcelApp.ActiveWorkbook.Worksheets(i).Select
' Debug.Print "--->" & ExcelApp.ActiveWorkbook.ActiveSheet.Name
' Debug.Print "--->" & ExcelApp.ActiveWorkbook.ActiveSheet.ChartObjects.Count
' Extract individual charts, if they exist
For j = 1 To ExcelApp.ActiveSheet.ChartObjects.Count
ExcelApp.ActiveWorkbook.ActiveSheet.ChartObjects(j).Chart.Export FileName:=CurDir & "\output\" & _
ExcelApp.ActiveWorkbook.ActiveSheet.Name & _
"_plot" & Format(j, "000") & "." & sType, FilterName:=sType
Next j
Next i
ExcelApp.ActiveWorkbook.Close SaveChanges:=False
ExcelApp.Quit
MsgBox "Done; it took " & Timer - Start & " seconds."
Exit Sub
ehandler:
MsgBox "Error = " & Error
End Sub
Private Sub cmdProcessExcel_Click()
Call ProcessExcelFile("c:\test\test_03.xlsx")
End Sub
Public Function ShellandWait(ExeFullPath As String, _
Optional TimeOutValue As Long = 0) As Boolean
Dim lInst As Long
Dim lStart As Long
Dim lTimeToQuit As Long
Dim sExeName As String
Dim lProcessId As Long
Dim lExitCode As Long
Dim bPastMidnight As Boolean
On Error GoTo ErrorHandler
lStart = CLng(Timer)
sExeName = ExeFullPath
'Deal with timeout being reset at Midnight
If TimeOutValue > 0 Then
If lStart + TimeOutValue < 86400 Then
lTimeToQuit = lStart + TimeOutValue
Else
lTimeToQuit = (lStart - 86400) + TimeOutValue
bPastMidnight = True
End If
End If
lInst = Shell(sExeName, vbMinimizedNoFocus)
lProcessId = OpenProcess(PROCESS_QUERY_INFORMATION, False, lInst)
Do
Call GetExitCodeProcess(lProcessId, lExitCode)
DoEvents
If TimeOutValue And Timer > lTimeToQuit Then
If bPastMidnight Then
If Timer < lStart Then Exit Do
Else
Exit Do
End If
End If
Loop While lExitCode = STATUS_PENDING
ShellandWait = True
ErrorHandler:
ShellandWait = False
Exit Function
End Function
Any help would be greatly appreciated.
Cheers
Rain
Bookmarks