Tạo msgbox để in sheet

  • Thread starter Thread starter bblove
  • Ngày gửi Ngày gửi
Liên hệ QC

bblove

Thành viên mới
Tham gia
24/3/09
Bài viết
11
Được thích
0
chào các bác, tình hình là em đã tạo msgbox, và đã làm 1 so function macro voi su giup do cua bac puzzy :) %#^#$
nhưng còn 1 vấn đè là em muon sau khi msgbox hien ra, em bam nut yes thi se print out cai sheet ra ngoài.

đay là doan code cua bài tap

PHP:
Option Explicit

Sub ShowMsgBox()
  DialogSheets("MsgBox").Show
End Sub
Sub Button2_Click()
Dim vtri As Long
'Dim Sh As Object
'Set Sh = ThisWorkbook.Sheets("Budget Control")
With Sheets("Budget Control")
vtri = IIf((.[B65536].End(xlUp).Row + 1) < 10, 10, .[B65536].End(xlUp).Row + 1)
    .Cells(vtri, "B") = [B7]            'Name
    .Cells(vtri, "C") = [B8]            'Dept
    .Cells(vtri, "D") = [F13]            'Details
    .Cells(vtri, "E") = [C9]            'From
    .Cells(vtri, "F") = [C11]            'To
    .Cells(vtri, "H") = [E18]           'Transportation
    .Cells(vtri, "I") = [E20]           'Hotel
    .Cells(vtri, "J") = [E22]           'Daily allowance
    .Cells(vtri, "K") = [E24]           'Others
End With
MsgBox "Completed!"
' em muon sau khi click OK thi se print out application form ra
ActiveWindow.SelectedSheets.PrintOut ' se khong work duoc vi active window dang la msgbox
Range("B7:B8,C9,C11,F13,E18:F25").ClearContents
[B7].Select
End Sub

Mấy bác làm ơn giúp dõ9 dùm em cai
 

File đính kèm

Chỉnh sửa lần cuối bởi điều hành viên:
Bạn dùng Dialog Sheet là gì cho mệt ra. Bạn thay thử doạn sau:
Code cũ:
Mã:
[COLOR=#000000][COLOR=#0000bb]Option Explicit 

Sub ShowMsgBox[/COLOR][COLOR=#007700]() 
  [/COLOR][COLOR=#0000bb]DialogSheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"MsgBox"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Show 
End Sub 
Sub Button2_Click[/COLOR][COLOR=#007700]() 
[/COLOR][COLOR=#0000bb]Dim vtri [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]Long 
[/COLOR][COLOR=#dd0000]'Dim Sh As Object 
'[/COLOR][COLOR=#0000bb]Set Sh [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]ThisWorkbook[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]With Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]vtri [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]IIf[/COLOR][COLOR=#007700]((.[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], .[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) 
    .[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"B"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Name 
    .Cells(vtri, "C") = [B8]            '[/COLOR][COLOR=#0000bb]Dept 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"D"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]F13[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Details 
    .Cells(vtri, "E") = [C9]            '[/COLOR][COLOR=#0000bb]From 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"F"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]C11[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'To 
    .Cells(vtri, "H") = [E18]           '[/COLOR][COLOR=#0000bb]Transportation 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"I"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E20[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Hotel 
    .Cells(vtri, "J") = [E22]           '[/COLOR][COLOR=#0000bb]Daily allowance 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"K"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E24[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Others 
End With 
MsgBox "Completed!" 
' [/COLOR][COLOR=#0000bb]em muon sau khi click OK thi se [/COLOR][COLOR=#007700]print [/COLOR][COLOR=#0000bb]out application form ra 
ActiveWindow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]SelectedSheets[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]PrintOut  se khong work duoc vi active window dang la msgbox 
Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B7:B8,C9,C11,F13,E18:F25"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]ClearContents 
[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]Select 
End Sub  [/COLOR][/COLOR]


Code sửa:
Mã:
[COLOR=#000000][COLOR=#0000bb]Option Explicit 
[/COLOR][COLOR=#0000bb]Sub Button2_Click[/COLOR][COLOR=#007700]() 
[/COLOR][/COLOR][COLOR=#000000][COLOR=#0000bb]dim qd as long[/COLOR][/COLOR]
[COLOR=#000000][COLOR=#0000bb]Dim vtri [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]Long 
[/COLOR][COLOR=#dd0000]'Dim Sh As Object 
'[/COLOR][COLOR=#0000bb]Set Sh [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]ThisWorkbook[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]With Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]vtri [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]IIf[/COLOR][COLOR=#007700]((.[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], .[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) 
    .[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"B"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Name 
    .Cells(vtri, "C") = [B8]            '[/COLOR][COLOR=#0000bb]Dept 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"D"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]F13[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Details 
    .Cells(vtri, "E") = [C9]            '[/COLOR][COLOR=#0000bb]From 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"F"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]C11[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'To 
    .Cells(vtri, "H") = [E18]           '[/COLOR][COLOR=#0000bb]Transportation 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"I"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E20[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Hotel 
    .Cells(vtri, "J") = [E22]           '[/COLOR][COLOR=#0000bb]Daily allowance 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"K"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E24[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Others 
End With 
[SIZE=2][U][COLOR=Blue][B]qd = MsgBox("Dong y in nhan OK.", vbOKCancel, "In Hoa Don")
If qd = 2 Then Exit Sub[/B][/COLOR][/U][/SIZE]
[/COLOR][U][B][COLOR=Blue]Sheets("Application")[/COLOR][COLOR=Blue].PrintOut From:=1, To:=1, Copies:=1, Collate:=True[/COLOR][/B][/U][COLOR=#0000bb] 
Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B7:B8,C9,C11,F13,E18:F25"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]ClearContents 
[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]Select 
End Sub  [/COLOR][/COLOR]
 
Lần chỉnh sửa cuối:
Upvote 0
Bạn dùng Dialog Sheet là gì cho mệt ra. Bạn thay thử doạn sau:
Code cũ:
Mã:
[COLOR=#000000][COLOR=#0000bb]Option Explicit 

Sub ShowMsgBox[/COLOR][COLOR=#007700]() 
  [/COLOR][COLOR=#0000bb]DialogSheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"MsgBox"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Show 
End Sub 
Sub Button2_Click[/COLOR][COLOR=#007700]() 
[/COLOR][COLOR=#0000bb]Dim vtri [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]Long 
[/COLOR][COLOR=#dd0000]'Dim Sh As Object 
'[/COLOR][COLOR=#0000bb]Set Sh [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]ThisWorkbook[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]With Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]vtri [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]IIf[/COLOR][COLOR=#007700]((.[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], .[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) 
    .[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"B"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Name 
    .Cells(vtri, "C") = [B8]            '[/COLOR][COLOR=#0000bb]Dept 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"D"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]F13[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Details 
    .Cells(vtri, "E") = [C9]            '[/COLOR][COLOR=#0000bb]From 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"F"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]C11[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'To 
    .Cells(vtri, "H") = [E18]           '[/COLOR][COLOR=#0000bb]Transportation 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"I"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E20[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Hotel 
    .Cells(vtri, "J") = [E22]           '[/COLOR][COLOR=#0000bb]Daily allowance 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"K"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E24[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Others 
End With 
MsgBox "Completed!" 
' [/COLOR][COLOR=#0000bb]em muon sau khi click OK thi se [/COLOR][COLOR=#007700]print [/COLOR][COLOR=#0000bb]out application form ra 
ActiveWindow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]SelectedSheets[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]PrintOut  se khong work duoc vi active window dang la msgbox 
Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B7:B8,C9,C11,F13,E18:F25"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]ClearContents 
[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]Select 
End Sub  [/COLOR][/COLOR]


Code sửa:
Mã:
[COLOR=#000000][COLOR=#0000bb]Option Explicit 
[/COLOR][COLOR=#0000bb]Sub Button2_Click[/COLOR][COLOR=#007700]() 
[/COLOR][/COLOR][COLOR=#000000][COLOR=#0000bb]dim qd as long[/COLOR][/COLOR]
[COLOR=#000000][COLOR=#0000bb]Dim vtri [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]Long 
[/COLOR][COLOR=#dd0000]'Dim Sh As Object 
'[/COLOR][COLOR=#0000bb]Set Sh [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]ThisWorkbook[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]With Sheets[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Budget Control"[/COLOR][COLOR=#007700]) 
[/COLOR][COLOR=#0000bb]vtri [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]IIf[/COLOR][COLOR=#007700]((.[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700], .[[/COLOR][COLOR=#0000bb]B65536[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlUp[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Row [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) 
    .[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"B"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Name 
    .Cells(vtri, "C") = [B8]            '[/COLOR][COLOR=#0000bb]Dept 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"D"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]F13[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'Details 
    .Cells(vtri, "E") = [C9]            '[/COLOR][COLOR=#0000bb]From 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"F"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]C11[/COLOR][COLOR=#007700]]            [/COLOR][COLOR=#dd0000]'To 
    .Cells(vtri, "H") = [E18]           '[/COLOR][COLOR=#0000bb]Transportation 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"I"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E20[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Hotel 
    .Cells(vtri, "J") = [E22]           '[/COLOR][COLOR=#0000bb]Daily allowance 
    [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Cells[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]vtri[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"K"[/COLOR][COLOR=#007700]) = [[/COLOR][COLOR=#0000bb]E24[/COLOR][COLOR=#007700]]           [/COLOR][COLOR=#dd0000]'Others 
End With 
[SIZE=2][U][COLOR=Blue][B]qd = MsgBox("Dong y in nhan OK.", vbOKCancel, "In Hoa Don")
If qd = 2 Then Exit Sub[/B][/COLOR][/U][/SIZE]
[/COLOR][U][B][COLOR=Blue]Sheets("Application")[/COLOR][COLOR=Blue].PrintOut From:=1, To:=1, Copies:=1, Collate:=True[/COLOR][/B][/U][COLOR=#0000bb] 
Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B7:B8,C9,C11,F13,E18:F25"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]ClearContents 
[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]B7[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]Select 
End Sub  [/COLOR][/COLOR]

Cám ơn bác đã chỉ dẫn, mình làm dược roi
bác oi,
+ nếu mình muon Print workbook thi sao ha bác?
+ nếu sheet 2 minh set password protect sheet, thi trong code minh làm thế nào đễ dữ liuệu có thể chuyển từ sheet 1 qua sheet 2 duoc vay bac'? sau khi chuyển qua thi sheet 2 van phai o chế độ password protect sheet
+ con 1 vấn đề nữa là : em muôn khi em nhập dữ vào mot cot nào đó, thi cot kế ben se thay đổi format.
Vidu: A1 = $5000 ( format Currency)
A2 = value ( em nhap vao) thi format ben A1 sẽ chuyển thành text
Bac oi, mong bác giup đ4 em thêm
 
Upvote 0
Xét từng trường hợp:

1/In Workbook: Với lệnh for each sheet là ta có thể in tất cả các trang tính có thể in, nhưng mình không hiểu in như vậy để làm gì.

2/Sửa trang protect bằng Code như sau:

Mã:
..........................
       ActiveSheet.Unprotect Password:="matkhau"
   ...........Làm gì thì làm
 ActiveSheet.Protect Password:="matkhau"
..........................
3/Thực sự không rõ ý đồ nên không tham gia được vì không khéo giải pháp thành đường vòng. Tốt nhất có ví dụ cụ thể.
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom