¦U¦ì¤j¤j¦n¡G
¤p§Ì¦³¤@°}¦CÂà´«ªº°ÝÃD¡A
¤@ª½¦Ê«ä¤£¸Ñ¡C¯S½Ð敎¦U¦ì¤j¤j¡C
¤p§Ì¬O·Qª½±µ§Q¥ÎTransposeÂà¸m¤è¦¡¨Ó逹¦¨
°}¦CªºÂà´«¡C¦ý¦]¸ê®Æ®w¤º³¡¥÷¦r¦ê·|¦bÂù¤Þ¸¹¤º¡C
¦p¦¹¡A¼vÅT¨ìTRANSPOSE°}¦CªºÂà´«¡C
½Ð°Ý¦bSQL»yªk¤¤¦p¦ó¤Þ¥ÎREPLACE±N
Âù¤Þ¸¹§ó§ï¬°³æ¤Þ¸¹©O¡H
»yªk¦p¤U¡G
Sub AA()
Dim myCon As New ADODB.Connection
Dim myRst As New ADODB.Recordset
Dim myCnc As String
Dim myCmd As String
Dim myFileName As String
Dim s1%, s2%
Dim mPath$
Dim mData, mData1
Dim mSht As Worksheet
mPath = "D:\TEMP"
myFileName = "TEMP-A.xls" '´ú¸ÕÀÉ
myCnc = "Driver={Microsoft Excel Driver (*.xls)};" & _
"DBQ=" & mPath & "\" & myFileName & ";"
myCmd = "SELECT ½s¸¹,¤ÀÃþ,¦W¦r,°ê¤å,¼Æ¾Ç,¦Xp FROM [F_Data01$]" '¦p¦ó¦b¦¹»yªk¤º¤Þ¥ÎREPLACE¨Ó¨ú¥N½s¸¹¡B¤ÀÃþ¡B¦W¦r¤ºªºÂù¤Þ¸¹©O¡H
myCon.Open "Provider=MSDASQL;" & myCnc
myRst.Open Source:=myCmd, ActiveConnection:=myCon
mData = myRst.GetRows 'AÄæ¦]³¡¥÷¦r¦ê¦³Âù¤Þ¸¹¦]¦ÓµLªk¨ú¥X¸ê®Æ
s1 = UBound(mData, 1)
s2 = UBound(mData, 2)
Set mSht = Worksheets(1)
mData1 = Application.Transpose(mData) 'µLªkÂà¸m °õ¦æ¶¥¬q¿ù»~13 ¡A«¬ºA¤£²Å¦X¡C
With mSht
.Range("a1").Resize(s2, s1) = mData1 'µLªkÂà¸m °õ¦æ¶¥¬q¿ù»~13 ¡A«¬ºA¤£²Å¦X¡C
End With
myRst.Close
myCon.Close
Set myRst = Nothing
Set myCon = Nothing
End Sub
³Æµù¡GÂù¤Þ¸¹¦b¦r¦ê¤º¨Ã«D¦³¤@©w³W«h
·P®¦¦U¦ì¤j¤j¡I |