Các bác hướng dẫn giúp em sửa lỗi add value từ text input vào header.
Em dùng hàm UNItoVBA chuyển chuỗi nhập từ txtcongty mà nó không hiển thị ra. trong khi gán cứng thì nó lại ra. Em cám ơn.
Em gửi kèm file và code ạ.
Code đây ạ:
==================
Private Sub btnbrowser_Click()
' Sub GettingFolder()
Dim SelectedFolder As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select folder"
.ButtonName = "Confirm"
.InitialFileName = "C:\"
If .Show = -1 Then
'ok clicked
SelectedFolder = .SelectedItems(1)
txtduongdan.Value = SelectedFolder
'MsgBox (SelectedFolder)
Else
'cancel clicked
End If
End With
End Sub
Private Sub btnnext_Click()
Dim chuoi, chuoimoi, congty, gdv As String
Dim i, j As Integer
'==== chuyen bien so sang format chung
chuoi = UCase(txtbks.Text)
chuoimoi = ""
For i = 1 To Len(chuoi)
If Mid(chuoi, i, 1) <> "-" And Mid(chuoi, i, 1) <> "." And Mid(chuoi, i, 1) <> "_" Then
chuoimoi = chuoimoi + Mid(chuoi, i, 1)
End If
Next i
If Len(chuoimoi) = 8 Then
chuoimoi = Left(chuoimoi, 3) + "-" + Mid(chuoimoi, 4, 3) + "." + Right(chuoimoi, 2)
Else
chuoimoi = Left(chuoimoi, 3) + "-" + Right(chuoimoi, 4)
End If
'=====================================
congty = UNItoVBA(txtcongty.Value)
' congty = "C" & ChrW(212) & "NG TY B" & ChrW(7842) & "O HI" & ChrW(7874) & "M NGH" & ChrW(7878) & " AN"
gdv = "Gi" & ChrW(225) & "m " & ChrW(273) & ChrW(7883) & "nh vi" & ChrW(234) & "n: "
ActiveWindow.View = xlPageLayoutView
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = "&""Times New Roman,Bold""&12" & congty _
& Chr(10) & "&""Times New Roman,Regular""&12" & gdv _
' & Chr(10) & "&""Times New Roman,Regular""&12 Ngay giam dinh: " & "20/12/2017 BKS: "
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
End With
Application.PrintCommunication = True
Range("A1").Select
'===========================================================
With Sheets("Data")
.Range("A3") = txtcongty.Text
.Range("A4") = txtgdv.Text
.Range("A5") = txtnggd.Text
.Range("A6") = chuoimoi
.Range("A7") = txtanhdau.Text
.Range("A8") = txtanhcuoi.Text
.Range("A9") = UNItoVBA(txtcongty.Text)
End With
UserForm1.Hide
End Sub
'=====================================================
'Chuyen chuoi tu UNICODE sang Code VBA
Function UNItoVBA(ByVal MyStr As String) As String
Dim Str As String, i As Integer, CStart As Integer, CCount As Integer, Status As Boolean
Str = "-225-224-7843-227-7841-259-7855-7857-7859-7861-7863-226-7845-7847-7849-7851-7853-273-233-232-7867-7869-7865-234-7871-7873-7875-7877-7879-237-236-7881-297-7883-243-242-7887-245-7885-244-7889-7891-7893-7895-7897-417-7899-7901-7903-7905-7907-250-249-7911-361-7909-432-7913-7915-7917-7919-7921-253-7923-7927-7929-7925-193-192-7842-195-7840-258-7854-7856-7858-7860-7862-194-7844-7846-7848-7850-7852-272-201-200-7866-7868-7864-202-7870-7872-7874-7876-7878-205-204-7880-296-7882-211-210-7886-213-7884-212-7888-7890-7892-7894-7896-416-7898-7900-7902-7904-7906-218-217-7910-360-7908-431-7912-7914-7916-7918-7920-221-7922-7926-7928-7924-10-"
For i = 1 To Len(MyStr)
If InStr(Str, "-" & AscW(Mid(MyStr, i, 1)) & "-") = 0 Then
If Not Status Then
CStart = i: Status = True
End If
CCount = CCount + 1
Else
If Status Then UNItoVBA = UNItoVBA & IIf(UNItoVBA = "", "", " & ") & """" & Replace(Mid(MyStr, CStart, CCount), """", """""") & """"
Status = False
CCount = 0
UNItoVBA = UNItoVBA & IIf(UNItoVBA = "", "", " & ") & "ChrW(" & AscW(Mid(MyStr, i, 1)) & ")"
End If
Next
If Status Then UNItoVBA = UNItoVBA & IIf(UNItoVBA = "", "", " & ") & """" & Replace(Mid(MyStr, CStart, CCount), """", """""") & """"
End Function
'===========================================
Private Sub Label1_Click()
End Sub
'============================================