اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

الردود الموصى بها

قام بنشر

السلام عليكم

عندي هذا الكود يفتح ملفات بي دي اف ولكن تظهر رسالة تحذير قبل فتح الملف كيف يمكنني التخلص من رسالة التحذير

    Dim strFile As String
    
On Error GoTo Failure
 
    strFile = Me.track
    If Len(Dir(strFile)) Then
        FollowHyperlink strFile
    Else
        MsgBox "no file found"
    End If
    Exit Sub
    
Failure:
    MsgBox err.Description
    err.Clear

وان كان هناك كود افضل منه فلا مانع المهم ان استطيع فتح ملف بي دي اف من النموذج

  • Thanks 1
قام بنشر
في ١٢‏/١١‏/٢٠١٨ at 09:10, عبد الله قدور said:

وان كان هناك كود افضل منه فلا مانع المهم ان استطيع فتح ملف بي دي اف من النموذج

اتفضل استاذ اليك هذا
 

Public Sub OpenDocument(DocPath As String)
	Dim A As Long
	A = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocPath, vbMaximizedFocus)
End Sub

Private Sub Command1_Click()
	Call OpenDocument("C:\Users\Shivan\Desktop\TEST.pdf")
End Sub

 

  • Like 4
  • Thanks 3
  • 4 years later...
قام بنشر
في 12‏/11‏/2018 at 10:32, Shivan Rekany said:
Public Sub OpenDocument(DocPath As String)
	Dim A As Long
	A = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocPath, vbMaximizedFocus)
End Sub

Private Sub Command1_Click()
	Call OpenDocument("C:\Users\Shivan\Desktop\TEST.pdf")
End Sub

احسنت اخي الكريم جزاك الله خيرا

 

  • أفضل إجابة
قام بنشر (معدل)

من مكتبتي .. أكواد لفتح الملفات الخارجية بدون رسائل تنبيه .. 🙂 

(1) :

Public Sub OpenFilePath(sFilePath As String)

CreateObject("Shell.Application").Namespace(0).ParseName(sFilePath).InvokeVerb "Open"

End Sub

(2) :

Public Sub OpenPath(strPath As String)

Shell "explorer.exe" & " " & strPath, vbNormalFocus


'You can also Change it to :
'
'Shell "explorer.exe" & " " & strPath, vbHide
'Shell "explorer.exe" & " " & strPath, vbMaximizedFocus
'Shell "explorer.exe" & " " & strPath, vbMinimizedFocus
'Shell "explorer.exe" & " " & strPath, vbMinimizedNoFocus
'Shell "explorer.exe" & " " & strPath, vbNormalNoFocus

End Sub

(3) :

Public Declare PtrSafe Function FileProtocolHandler Lib "url.dll" _
      Alias "FileProtocolHandlerA" (ByVal hwnd As Long, ByVal hinst As Long, _
      ByVal lpszCmdLine As String, ByVal nShowCmd As Long) As Long

Public Sub OpenHyperlink(ByVal Url)
  FileProtocolHandler 0, 0, Url, 1
End Sub

Sub test()
OpenHyperlink ("D:\Testing")
End Sub

(4) : دالة ShellExecute لتشغيل البرامج أو الملفات الخارجية بدون رسائل مزعجة

'=======================================(الدالة)
Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3

Public Declare Ptrsafe Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _
  (ByVal hwnd As Long, _
   ByVal lpOperation As String, _
   ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String, _
   ByVal nShowCmd As Long) As Long


'=======================================
http://www.rdpslides.com/pptfaq/FAQ00479_ShellExecute_Example.htm
'=======================================
https://stackoverflow.com/questions/1374433/shellexecuteex-in-vba
'=======================================

'SW_HIDE                Hides the window.
'SW_MAXIMIZE            Maximizes the window.
'SW_MINIMIZE            Minimizes the window.
'SW_RESTORE             Restores the window to normal (not maximized or minimized) size.
'SW_SHOW                Activates the window and displays it at its current size.
'SW_SHOWDEFAULT         Displays the window at a default size.
'SW_SHOWMAXIMIZED       Displays the window maximized.
'SW_SHOWMINIMIZED       Displays the window minimized.
'SW_SHOWMINNOACTIVE     Displays the window minimized without giving it the focus.
'SW_SHOWNA              Displays the window at its current size without giving it the focus.
'SW_SHOWNOACTIVATE      Displays the window in its most recent size and position without giving it the focus.
'SW_NORMAL              Displays the window at normal (not minimized or maximized) size.


'============================================================(طرق الاستدعاء)
Some particularly useful combinations include:

Open a folder in a folder view:
ShellExecute hWnd, "open", "C:\whatever", vbNullString, vbNullString, SW_SHOWNORMAL

Explore a folder with Windows Explorer:
ShellExecute hWnd, "explore", "C:\whatever", vbNullString, vbNullString, SW_SHOWNORMAL

Launch the Find utility from a particular directory:
ShellExecute hWnd, "find", "C:\whatever", vbNullString, vbNullString, SW_SHOWNORMAL

Display a Web page in the system's default browser:
ShellExecute hWnd, "open", "C:\whatever\test.html", vbNullString, vbNullString, SW_SHOWNORMAL

(5) :دالة ShellWait لفتح الملفات الخارجية والإنتظار حتى تنتهي المهمة

'-----------------------------------------------------------------------------------www.officena.net-----'
'                                               __  __                                     _             '
'                                              / _|/ _|                                   | |            '
'           __      ____      ____      _____ | |_| |_(_) ___ ___ _ __   __ _   _ __   ___| |_           '
'           \ \ /\ / /\ \ /\ / /\ \ /\ / / _ \|  _|  _| |/ __/ _ \ '_ \ / _\`| | '_ \ / _ \ __|          '
'            \ V  V /  \ V  V /  \ V  V / (_) | | | | | | (_|  __/ | | | (_| |_| | | |  __/ |_           '
'             \_/\_/    \_/\_/    \_/\_(_)___/|_| |_| |_|\___\___|_| |_|\__,_(_)_| |_|\___|\__|          '
'                                                                   Developed By Mohammed Essam          '
'------www.officena.net----------------------------------------------------------------------------------'
Option Compare Database
Option Explicit

'***************** Code Start ******************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Terry Kreft
Private Const STARTF_USESHOWWINDOW& = &H1
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

#If VBA7 And Win64 Then
Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal _
    hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
Private Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal _
    lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
    lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    PROCESS_INFORMATION) As Long
    
Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal _
    hObject As Long) As Long
#Else
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
    hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
    lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
    lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    PROCESS_INFORMATION) As Long
    
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
    hObject As Long) As Long
#End If


Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
    Dim proc As PROCESS_INFORMATION
    Dim Start As STARTUPINFO
    Dim Ret As Long
    ' Initialize the STARTUPINFO structure:
    With Start
        .cb = Len(Start)
        If Not IsMissing(WindowStyle) Then
            .dwFlags = STARTF_USESHOWWINDOW
            .wShowWindow = WindowStyle
        End If
    End With
    ' Start the shelled application:
    Ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
            NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc)
    ' Wait for the shelled application to finish:
    Ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    Ret& = CloseHandle(proc.hProcess)
End Sub
'***************** Code End ****************

وتناديها

ShellWait("C:\MyApp.exe", vbNormalFocus)

 

 

أختر اللي يعجبك منها 😁

تم تعديل بواسطه Moosak
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information