返回列表 上一主題 發帖

EXCEL貼入網頁問題

回復 1# die78325
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim R, 字串 As String, S As String
  4.     For Each R In [A1:H10].Rows
  5.         S = Join(Application.Transpose(Application.Transpose(R)), " ")
  6.         字串 = IIf(字串 = "", S, 字串 & Chr(10) & S)
  7.    Next
  8.    '
  9.    '
  10.    
  11.   ' With .Document
  12.    '     .getElementsByName("q11")(0).Value = 字串   ' 找到q11欄位填入
  13.   'End With

  14. End Sub
複製代碼

TOP

回復 4# die78325
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ar(), 字串 As String, xi As Integer, xii As Integer, S As String, Rng As Range
  4.     'With Range("A1").CurrentRegion
  5.     'CurrentRegion 屬性  傳回 Range 物件,該物件代表目前的區域。目前區域是指以任意空白列及空白欄的組合為邊界的範圍。唯讀
  6.     'MsgBox .Address
  7.     Set Rng = Sheet1.[a1]
  8.     With Sheet1.Range(Rng.Address, Cells(Rng.End(xlDown).Row, Rng.End(xlToRight).Column).Address)
  9.         MsgBox .Address(, , , 1, 1)
  10.         Ar = .Value
  11.         For xi = 1 To .Rows.Count
  12.             For xii = 1 To .Columns.Count
  13.                 Ar(xi, xii) = IIf(.Cells(xi, xii) <> "", .Cells(xi, xii).Text, vbTab)
  14.             Next
  15.         Next
  16.         For xi = 1 To UBound(Ar)
  17.             S = Join(Application.Transpose(Application.Transpose(Application.Index(Ar, xi))), vbTab)
  18.             字串 = IIf(字串 = "", S & vbLf, 字串 & vbLf & S)
  19.         Next
  20.         MsgBox 字串
  21.    End With
  22. '  '
  23.    '
  24.    
  25.   ' With .Document
  26.    '     .getElementsByName("q11")(0).Value = 字串   ' 找到q11欄位填入
  27.   'End With

  28. End Sub
複製代碼

TOP

回復 6# die78325
這些並不難,不了解的可多看VBA的說明

TOP

回復 8# die78325
DataObject 物件
在進行轉換動作時,做為格式化文字資料的暫存區域。其也可以暫存和儲存在 DataObject 的文字片段相關的格式。
  1. Option Explicit
  2. Sub Ex()  '使用DataObject 物件
  3.     Dim Rng As Range
  4.     'Dim Clip As New DataObject
  5.     ' New DataObject:  VBA需設定引用 Microsoft Forms 2.0 Object Library
  6.     Dim Clip As Object  '不需設定引用 Microsoft Forms 2.0 Object Library
  7.     Set Clip = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  8.     Set Rng = Sheet1.[a1]
  9.     Sheet1.Range(Rng.Address, Cells(Rng.End(xlDown).Row, Rng.End(xlToRight).Column).Address).Copy
  10.     Clip.GetFromClipboard
  11.     '
  12.     '
  13.    
  14.    With .Document
  15.         .getElementsByName("q11")(0).Value = Clip.GetText(1)    ' 找到q11欄位填入
  16.   End With

  17. End Sub
複製代碼

TOP

        靜思自在 : 能付出愛心就是福,能消除煩惱就是慧。
返回列表 上一主題