返回列表 上一主題 發帖

寫一個另存新檔的巨集,但是需要.pdf file,那麼應怎改寫?

Selection.Resize(, 13).Copy Sheets("invoice").Selection.Resize(, 13)
Selection.Resize(, 13).Copy Sheets("invoice").Selection.Resize(, 1).Paste
Selection.Resize(, 13).Copy Sheets("invoice").Range("B13").Select

TOP

我的是2010

vba3.jpg (59.36 KB)

vba3.jpg

TOP

本帖最後由 Blade 於 2014-1-21 19:16 編輯

當我選了,保護工作表,以下程式便會出錯誤。
  1. Sub InvoiceNo()
  2.     Dim xRNo As Range, i As Integer, y As Integer, R As Integer, RR As Integer
  3.     Set xRNo = Range("Q2")
  4.     'Set xRNo = Range("D5")
  5.     y = Len(xRNo)                                      '[發票編號]的字串個數
  6.     For i = 1 To y
  7.         If R = 0 And Mid(xRNo, i, 1) Like "[0-9]" Then R = i    '找[發票編號]中第一個數字
  8.         If Mid(xRNo, i, 1) Like "[!0-9]" Then RR = i            '找[發票編號]中最後的文字
  9.     Next
  10.     If RR > R Or R = 0 Or xRNo = 0 Then  '數字在文字之前(或只有文字),只有數字
  11.         MsgBox "【注意】收據編號出錯 !!!"
  12.    Else
  13.         xRNo = Mid(xRNo, 1, R - 1) & Format(Mid(xRNo, R) + 1, String((y - R + 1), "0"))
  14.     End If
  15.    
  16.     Range("Q2").Select
  17.   'Range("D5").Select
  18.     Selection.Copy
  19.     Range("D6").Select
  20.     ActiveSheet.Paste
  21.     Application.CutCopyMode = False
  22.     With Selection.Font
  23.         .ColorIndex = xlAutomatic
  24.         .TintAndShade = 0
  25.     End With
  26.     Range("A4").Select
  27.      '如  y - R + 1 = 5
  28.      '如 :Format(568, String((y - R + 1), "0")) => Format(568, "00000") => 5位數:  00568
  29. End Sub
複製代碼
出錯誤的句子
  1.         xRNo = Mid(xRNo, 1, R - 1) & Format(Mid(xRNo, R) + 1, String((y - R + 1), "0"))
複製代碼

TOP

        靜思自在 : 心中常存善解、包容、感思、知足、惜福。
返回列表 上一主題