返回列表 上一主題 發帖

等待上一程式完成, 才執行下一段程式

等待上一程式完成, 才執行下一段程式

有一vba 需讀取 ms sql 資料, 及複制到另一工作頁,
但由於讀取 ms sql 資料仍未更新完成, 已複制空白資料到新一頁,
有何方式等待上一程執行完成, (更新資料)才再執行,
50 字節以內
不支持自定義 Discuz! 代碼

回復 1# sammyc
試試看
Selection.QueryTable.Refresh BackgroundQuery:=False

TOP

回復 2# GBKEE

執行到此句, 卞現錯誤
  1. Sub l_style()
  2. '
  3.     Dim ST_NO
  4.     ST_NO = Application.InputBox("輸入款號", "輸入款號", "", 200, 100)
  5.     ST_NO = UCase(ST_NO)
  6.    
  7. '    Sheets("stylebom").Select
  8. 'Cells(2, 2) = "& st_no"

  9.     Sheets("stylebom").Range("E3") = ST_NO


  10.    
  11.     Application.CutCopyMode = False
  12.     With ActiveWorkbook.Connections( _
  13.         "192.168.101.203 Garment01 TxProjMatStyCons").OLEDBConnection
  14.         .BackgroundQuery = True
  15.         .CommandText = Array(  "SELECT  * from table 1 where style = '" & ST_NO & "'"  )
  16.         .CommandType = xlCmdSql
  17.         .Connection = Array( _
  18.         "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=Garment01;Data Source=192.16" _
  19.         , _
  20.         "8.101.203;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=CWST021;Use Encryption for Data=False;" _
  21.         , "Tag with column collation when possible=False")
  22.         .RefreshOnFileOpen = False
  23.         .SavePassword = False
  24.         .SourceConnectionFile = ""
  25.         .SourceDataFile = ""
  26.         .ServerCredentialsMethod = xlCredentialsMethodIntegrated
  27.     End With
  28.     With ActiveWorkbook.Connections( _
  29.         "192.168.101.203 DtradeSimpleGarment01 TxProjMatStyCons")
  30.         .Name = "192.168.101.203 DtradeSimpleGarment01 TxProjMatStyCons"
  31.         .Description = ""
  32.     End With
  33.     ActiveWorkbook.Connections( _
  34.         "192.168.101.203 DtradeSimpleGarment01 TxProjMatStyCons").Refresh
  35.             Selection.QueryTable.Refresh BackgroundQuery:=False
  36. Call c_new
  37. End Sub
複製代碼
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 3# sammyc
試試看
ActiveWorkbook.Connections("192.168.101.203 DtradeSimpleGarment01 TxProjMatStyCons").Refresh  BackgroundQuery:= False

TOP

仍是不行, 行到此時出錯誤
50 字節以內
不支持自定義 Discuz! 代碼

TOP

        靜思自在 : 發脾氣是短暫的發瘋。
返回列表 上一主題