你用什么方法打开EXCEL文件是SHELL函数还是调用CREATEOBJECT(EXECL.APPLICATION)?

解决方案 »

  1.   

    如果你是人工修改EXCEL 文件的话建议用SHELL函数打开EXCEL文件!
      

  2.   

    TO:water_j(jxp)
    我用的是CREATOBJECT方法,请问用SHELL方法如何实现,可否具体点,用CREATOBJECT方法为什么会存在该问题?
      

  3.   

    建议用VB API函数
    Public Declare 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
    Dim x As Long
    Dim DataPath As String
    DataPath = App.Path & "\mobs.xls"
    x = ShellExecute(hwnd, "Open", DataPath, "", "", 1)
    这样人工修改应该没有问题!
      

  4.   

    TO:water_j(jxp) 
    请问函数执行后返回的X是什么,如何用X对EXCEL文件中的中的数据进行操作,如何获得一个EXCEL文件中的某一SHEET的引用?
      

  5.   

    x是SHELLEXECUTE 的返回值可以用来判断函数执行的情况!
    SHELLEXECUTE函数无法实现对某一SHEET的引用(只能打开默认的SHEET,一般是SHEET1)
    这时只能用CREATEOBJECT调用对象了!
      

  6.   

    具体SHELLEXECUTE 的返回值如下:
    Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. 0  The operating system is out of memory or resources. 
    ERROR_FILE_NOT_FOUND  The specified file was not found. 
    ERROR_PATH_NOT_FOUND  The specified path was not found. 
    ERROR_BAD_FORMAT  The .exe file is invalid (non-Win32® .exe or error in .exe image). 
    SE_ERR_ACCESSDENIED  The operating system denied access to the specified file.  
    SE_ERR_ASSOCINCOMPLETE  The file name association is incomplete or invalid. 
    SE_ERR_DDEBUSY  The DDE transaction could not be completed because other DDE transactions were being processed. 
    SE_ERR_DDEFAIL  The DDE transaction failed. 
    SE_ERR_DDETIMEOUT  The DDE transaction could not be completed because the request timed out. 
    SE_ERR_DLLNOTFOUND  The specified dynamic-link library was not found.  
    SE_ERR_FNF  The specified file was not found.  
    SE_ERR_NOASSOC  There is no application associated with the given file name extension. 
    SE_ERR_OOM  There was not enough memory to complete the operation. 
    SE_ERR_PNF  The specified path was not found. 
    SE_ERR_SHARE  A sharing violation occurred 
      

  7.   

    TO:water_j(jxp) 
    非常感谢你的帮助,希望通过你的方法能解决问题,周一验证后给分.