返回列表 上一主題 發帖

一個複雜的表單問題

回復 1# 317

流程總覺得有點不順,試試看有問題再討論
員工資料.rar (520.77 KB)
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2012-7-26 15:12 編輯

回復 4# 317

我測試沒問題,可能你沒有將檔案解壓縮到電腦位置
導致沒有權限寫入檔案
play.gif
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2012-7-26 21:23 編輯

回復 7# 周大偉

PictureSizeMode屬性控制
play.gif
學海無涯_不恥下問

TOP

回復 10# 周大偉

直接排序即可
  1. Private Sub Label1_Click() '新增資料
  2. Dim Ar(), A As Range, B As Range, C As Range
  3. Set C = Sheet1.[A:A].Find(TextBox1.Text, lookat:=xlWhole)
  4. If Not C Is Nothing Then MsgBox ("學號重複,請重新檢查"): Exit Sub
  5. fd = ThisWorkbook.Path & "\"
  6. If Dir(fd & "Temp.bmp") <> "" Then Kill fd & "Temp.bmp"
  7. SavePicture Image1.Picture, fd & "Temp.bmp"
  8. obs = Array("TextBox1", "TextBox2", "TextBox3", "TextBox4", "TextBox5", "TextBox6", "ComboBox1", "TextBox7", "TextBox8", "TextBox9", "TextBox10", "TextBox11", "ComboBox2")

  9. For i = 0 To 12
  10.      ReDim Preserve Ar(i)
  11.      Ar(i) = Controls(obs(i)).Text
  12. Next
  13. With Sheet1
  14.    Set A = .Cells(.Rows.Count, 1).End(xlUp).Offset(1)
  15.    A.RowHeight = 79.8
  16.    Set B = A.Offset(, 13)
  17.    A.Resize(, 13) = Ar
  18.    .Shapes.AddPicture fd & "Temp.bmp", msoFalse, msoCTrue, B.Left, B.Top, B.Width, B.Height
  19.     .Range("A3").CurrentRegion.Sort key1:=.[A4], header:=xlYes  '排序
  20. End With
  21. Unload Me: UserForm1.Show
  22. End Sub
複製代碼
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2012-8-7 00:13 編輯

回復 12# 周大偉
圖片格式的預設值是大小位置隨儲存格而變

    play.gif
為確保圖片會隨儲存格移動
  1. Private Sub Label1_Click() '新增資料
  2. Dim Ar(), A As Range, B As Range, C As Range, MyPic As Shape
  3. Set C = Sheet1.[A:A].Find(TextBox1.Text, lookat:=xlWhole)
  4. If Not C Is Nothing Then MsgBox ("學號重複,請重新檢查"): Exit Sub
  5. fd = ThisWorkbook.Path & "\"
  6. If Dir(fd & "Temp.bmp") <> "" Then Kill fd & "Temp.bmp"
  7. SavePicture Image1.Picture, fd & "Temp.bmp"
  8. obs = Array("TextBox1", "TextBox2", "TextBox3", "TextBox4", "TextBox5", "TextBox6", "ComboBox1", "TextBox7", "TextBox8", "TextBox9", "TextBox10", "TextBox11", "ComboBox2")

  9. For i = 0 To 12
  10.      ReDim Preserve Ar(i)
  11.      Ar(i) = Controls(obs(i)).Text
  12. Next
  13. With Sheet1
  14.    Set A = .Cells(.Rows.Count, 1).End(xlUp).Offset(1)
  15.    A.RowHeight = 79.8
  16.    Set B = A.Offset(, 13)
  17.    A.Resize(, 13) = Ar
  18.    Set MyPic = .Shapes.AddPicture(fd & "Temp.bmp", msoFalse, msoCTrue, B.Left, B.Top, B.Width, B.Height)
  19.    MyPic.Placement = xlMoveAndSize  '設定圖片大小位置隨儲存格改變
  20.    .Range("A3").CurrentRegion.Sort key1:=.[A4], header:=xlYes  '排序
  21. End With
  22. Unload Me: UserForm1.Show
  23. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 14# 周大偉

我測試是沒問題,有動畫為證
至於你還有問題存在,不妨上傳您的檔案看看
學海無涯_不恥下問

TOP

回復 17# 周大偉
我測試沒問題
是否你沒注意到會自動編號的問題所導致呢?
play.gif
學海無涯_不恥下問

TOP

回復 19# 周大偉
自動編號是在表單初始化的事件中,你要試著去了解修改
至於圖片是否可以排序
手動排序看看就知道了
play.gif
學海無涯_不恥下問

TOP

回復 21# 周大偉
  1. Private Sub Label1_Click() '新增資料

  2. Dim Ar(), A As Range, B As Range, C As Range, MyPic As Shape
  3. Set dpic = CreateObject("Scripting.Dictionary")

  4. Set C = Sheet1.[A:A].Find(TextBox1.Text, lookat:=xlWhole)

  5. If Not C Is Nothing Then MsgBox ("學號重複,請重新檢查"): Exit Sub

  6. fd = ThisWorkbook.Path & "\"

  7. If Dir(fd & "Temp.bmp") <> "" Then Kill fd & "Temp.bmp"

  8. SavePicture Image1.Picture, fd & "Temp.bmp"

  9. obs = Array("TextBox1", "TextBox2", "TextBox3", "TextBox4", "TextBox5", "TextBox6", "ComboBox1", "TextBox7", "TextBox8", "TextBox9", "TextBox10", "TextBox11", "ComboBox2")


  10. For i = 0 To 12

  11.      ReDim Preserve Ar(i)

  12.      Ar(i) = Controls(obs(i)).Text

  13. Next

  14. With Sheet1

  15.    Set A = .Cells(.Rows.Count, 1).End(xlUp).Offset(1)

  16.    A.RowHeight = 79.8

  17.    Set B = A.Offset(, 13)

  18.    A.Resize(, 13) = Ar

  19.    Set MyPic = .Shapes.AddPicture(fd & "Temp.bmp", msoFalse, msoCTrue, B.Left, B.Top, B.Width, B.Height)

  20.    For Each pic In Sheet1.Shapes
  21.       If pic.Type = 13 Then dpic(.Cells(pic.TopLeftCell.Row, 1).Value) = pic.Name
  22.    Next

  23.    .Range("A3").CurrentRegion.Sort key1:=.[A4], Header:=xlYes  '排序
  24.    If Val(Application.Version) > 11 Then
  25.       For Each A In .Range(.[A4], .Cells(.Rows.Count, 1).End(xlUp))
  26.           .Shapes(dpic(A.Value)).Top = A.Top
  27.       Next
  28.     End If

  29. End With

  30. Unload Me: UserForm1.Show

  31. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 對父母要知恩,感恩、報恩。
返回列表 上一主題