1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Declare PtrSafe Function GetSystemMetrics32 Lib "User32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Declare PtrSafe Function MoveWindow Lib "User32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Function OuvrirFichier2(MonFichier As String, Optional ByVal extension As String)
'par Excel-Malin.com ( https://excel-malin.com )
'On Error GoTo OuvertureFichierErreur
'vérifie si le fichier existe
If Dir(MonFichier & extension) <> "" Then
extension1 = extension
vue = True
Else
If Dir(MonFichier & ".xls") <> "" Then
extension1 = ".xls"
vue = True
Else
If Dir(MonFichier & ".xlsm") <> "" Then
extension1 = ".xlsm"
vue = True
Else
If Dir(MonFichier & ".xlsx") <> "" Then
extension1 = ".xlsx"
vue = True
Else
If Len(Dir(MonFichier, vbDirectory)) <> "" Then
vue = False
Else
OuvrirFichier2 = False
MsgBox "pas de fichier ou dossier trouver pour " & MonFichier
Exit Function
End If
End If
End If
End If
End If
'ouvre le fichier dans son application associée
Dim MonApplication As Object
Set MonApplication = CreateObject("Shell.Application")
retval = MonApplication.Open(MonFichier & extension1)
largeur = GetSystemMetrics32(0)
hauteur = GetSystemMetrics32(1)
If vue = True Then
cal_largeur = largeur - 400
cal_hauteur = ((hauteur / 4) * 2)
With Application
.WindowState = xlNormal
.Left = 0
.Top = hauteur / 4 - 25
.Width = cal_largeur
.Height = cal_hauteur
End With
Else
T = Timer + 10
Do While T >= Timer
Do: DoEvents: Loop While objshell.Windows.Count = nbfenetre: 'pos = Split(mespositions(x), ",")
MoveWindow FindWindow(vbNullString, objshell.Windows(nbfenetre).locationname), 0, 0, largeur, hauteur / 4, 1
Loop
End If
OuvrirFichier2 = True
Set MonApplication = Nothing
Exit Function
OuvertureFichierErreur:
Set MonApplication = Nothing
OuvrirFichier2 = False
End Function |
Partager