(1)、我在Excel中开发了个宏程序包括两个模块,现在的问题是我每次要在另外一个Excel表格中执行此宏程序,所以我每次都不得不把这两个模块导入到Excel表格中然后执行,客户说这个不行,要求做一个窗体能把宏程序导入到Excel文件中,这样的话打开这个新Excel文件时就可以直接运行宏了,请教怎么实现
(2)、我需要一个打开对话框,由于加载需要的DLL时出现问题,于是我改为API实现打开一个对话框,但是这个打开对话框不是当前激活状态,也就是说不在最上层,请教该怎么办?
请高手帮帮忙,分不够我可以再加!!!

解决方案 »

  1.   

    第一,你可以把你的程序做xla加载宏。加载入系统后无论打开那一个excel都有效。
    第二:参考以下代码
    顯示打開或保存文件窗口Private Type OPENFILENAME
      lStructSize        As Long
      hwndOwner          As Long
      hInstance          As Long
      lpstrFilter        As String
      lpstrCustomFilter  As String
      nMaxCustFilter     As Long
      nFilterIndex       As Long
      lpstrFile          As String
      nMaxFile           As Long
      lpstrFileTitle     As String
      nMaxFileTitle      As Long
      lpstrInitialDir    As String
      lpstrTitle         As String
      flags              As Long
      nFileOffset        As Integer
      nFileExtension     As Integer
      lpstrDefExt        As String
      lCustData          As Long
      lpfnHook           As Long
      lpTemplateName     As String
    End TypePrivate Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ 
                             "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _ 
                             "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As LongPublic Function LoadFile(Optional Title As String = "Open File")
      Dim ofn As OPENFILENAME
      ofn.lStructSize = Len(ofn)
      ofn.hwndOwner = 0 'Form1.hwnd
      ofn.hInstance = 0 'App.hInstance
      ofn.lpstrFilter = "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0) + "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0)
      ofn.lpstrFile = Space$(254)
      ofn.nMaxFile = 255
      ofn.lpstrFileTitle = Space$(254)
      ofn.nMaxFileTitle = 255
      ofn.lpstrInitialDir = CurDir
      ofn.lpstrTitle = Title
      ofn.flags = 0  '0-獨占方式開啟   1-唯讀方式開啟  6148-不顯示開啟方式
      If GetOpenFileName(ofn) Then
         LoadFile = Trim$(ofn.lpstrFile)
      Else
         LoadFile = vbNullString
      End If
    End Function
      

  2.   

    http://community.csdn.net/expert/Topicview2.asp?id=5183833
    don't crosspost