Excel database from WEB in VBA - excel

I would like to make a database of all companies from my city in Excel from this site: http://panoramafirm.pl/szukaj/małopolskie,olkuski,olkusz/firmy,1
There are 25 records in every page.
The last number in link is a number of page. Here I've 114 pages and I would like to copy every record from this site to Excel.
After 95 records something goes wrong. The 95th record is overwriting until macro ends up.
Sub dwln2()
Dim IE As InternetExplorer
Dim i As Integer
Dim xlNowy As Worksheet
Dim x As Integer
i = 1
Z = InputBox("Page from", "Warning", 1)
x = InputBox("Page to", "Warning", 5)
ActiveSheet.Name = "Olkusz" & x
For x = Z To x
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate "http://panoramafirm.pl/szukaj/malopolskie,olkuski,olkusz/firmy," & x & ".html"
Do While IE.readyState <> 4
DoEvents
Loop
For Each el In IE.document.all
If el.className = "noLP companyName colorBlue addax addax-cs_hl_hit_company_name_click" Then
Cells(i, 1) = el.Text
End If
If el.className = "noLP addax addax-cs_hl_hit_homepagelink_click icon-link-ext colorBlue" Then
Cells(i, 2) = el.innerText
End If
If el.className = "icon-phone addax addax-cs_hl_hit_phone_number_click noLP highlightOnHover" Then
Cells(i, 3) = el.innerText
End If
If el.className = "contacts" Then
Cells(i, 4) = el.innerText
End If
If el.className = "noLP addax addax-cs_hl_email_submit_click icon-mail titleEmail ajaxGemius colorBlue highlightOnHover" Then
Cells(i, 5) = el.innerText
End If
If el.className = "text hidePhone crl" Then
Cells(i, 6) = el.innerText
i = i + 1
End If
Next
Set IE = Nothing
Columns.Select
Columns.EntireColumn.AutoFit
Cells.Select
Cells.EntireRow.AutoFit
Next
MsgBox "Done"
End Sub
Second problem is that I don't know how to close InternetExplorer before opening next window. Is there any option to open pages in tabs?

Page 95 doesn't have an element with the classname text hidePhone crl
Sub dwln2()
Dim IE As InternetExplorer
Dim i As Long
Dim data
Dim xlNowy As Worksheet
Dim x As Integer
Z = InputBox("Page from", "Warning", 1)
x = InputBox("Page to", "Warning", 5)
ActiveSheet.Name = "Olkusz" & x
ReDim data(1 To (x - Z + 2) * 25, 1 To 6)
Set IE = New InternetExplorer
For x = Z To x
IE.Visible = True
IE.Navigate "http://panoramafirm.pl/szukaj/malopolskie,olkuski,olkusz/firmy," & x & ".html"
Do While IE.readyState <> 4
DoEvents
Loop
For Each el In IE.document.all
Select Case el.className
Case "noLP companyName colorBlue addax addax-cs_hl_hit_company_name_click"
i = i + 1
data(i, 1) = el.innerText
Case "noLP addax addax-cs_hl_hit_homepagelink_click icon-link-ext colorBlue"
data(i, 2) = el.innerText
Case "icon-phone addax addax-cs_hl_hit_phone_number_click noLP highlightOnHover"
data(i, 3) = el.innerText
Case "contacts"
data(i, 4) = el.innerText
Case "noLP addax addax-cs_hl_email_submit_click icon-mail titleEmail ajaxGemius colorBlue highlightOnHover"
data(i, 5) = el.innerText
Case "text hidePhone crl"
data(i, 6) = el.innerText
End Select
Next
Next
IE.Quit
Set IE = Nothing
Cells.Clear
Range("A1").Resize(UBound(data, 1), 6) = data
Columns.AutoFit
Rows.AutoFit
MsgBox "Done"
End Sub

Related

How do I split the output of an excel report when collecting input with a user form and exporting to PDF?

I am trying to create a front-end form that can be filled out by a user, which will then populate a back-end spreadsheet the user cannot edit. This spreadsheet needs to follow a standard layout that I have already created, and the form will populate predetermined cells (or will create cells following the layout) based on user input from the form. I also need the form to be able to add/repeat questions, as well as duplicate sections in the spreadsheet based on user input requirements ("Do you need to add a section? [Yes/No]" //If [Yes], then duplicate section, repeat questions in form; if [No], then export data to spreadsheet, exit form). The spreadsheet layout consists of sections. The number of sections/cells per section required will vary from user to user, but the type of data will typically remain the same, and therefore should be able to choose the name of the field from a list of some sort (drop down?) However, the user may need to create a custom name for a field. I also need the form to be able to automatically adjust cell sizes based on the amount of text for that value. It is important that this form is printable, and does not separate sections from page to page. Furthermore, each "Notes" field will vary in size, and should be automatically resized to only show the existing text, plus one blank line for hand-written notes. I would also like the form to prompt the user to indicate whether a field is needed (some fields will be permanent, and the user will not be prompted about these fields). If the field is not needed, I need the form to exclude it from the final output.
I am open to suggestions on how to design this project differently than I have already (for example, using alternate programs/software/coding languages).
So far, however, I have created a user form in Excel that collects data and inputs it into a spreadsheet, which can then be exported to a PDF report using a set format/layout on another sheet of the workbook. The layout consists of a "Header" section and an "Item" section. In the form, the user can input a single job number and multiple item numbers, and when they export the report, the code prints the job number in the provided layout for the header, and then loops through the item numbers and copies and populates the item section for as many items as the user has provided. In the exported PDF, however, the item section gets split between pages, regardless of page orientation (landscape orientation is preferred). How do I prevent the "Item" section from being broken up between pages?
Option Explicit
Dim ctl As Control
Dim rCell As Range
Dim img As Picture
Dim newrow As ListRow
Dim tbl1 As ListObject
Dim msgValue As VbMsgBoxResult
Dim ary As Variant, aryx As Variant
Dim ws2 As Worksheet, ws1 As Worksheet
Dim s As String, FilePath As String, user As String, pFilename As String, part As String
Dim x As Long, sc As Long, j As Long, ctr As Long, rctr As Long, tbl1row As Long, r As Long, t As Long, items As Long, y As Long, ctrx As Long
Private Sub cmdCLEAR_Click()
MsgBox ("This action only clears the form NOT the record" & vbCrLf & "Ready for adding NEW entry."), vbOKOnly, "Clear Form "
CLEARFORM
Me.cmdADD.Enabled = True
Me.TextBox6.SetFocus
End Sub
Sub CLEARFORM()
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "TextBox"
ctl.Text = ""
Case "ComboBox"
ctl.ListIndex = -1
ctl.Value = ""
End Select
Next ctl
Me.Image1.Picture = LoadPicture("") '*********clears picture******
End Sub
Private Sub cmdADD_Click()
For x = 1 To 35
If Controls("TextBox" & x).Text = "" Then
MsgBox "Data field missing", vbCritical, "Data missing"
Exit Sub
End If
Next x
msgValue = MsgBox("Do want to add another item?", vbYesNo + vbQuestion, "Next Item ?")
If msgValue = vbYes Then
SAVEDATANEXT
For x = 16 To 35
Me.Controls("TextBox" & x).Text = ""
Next x
Me.TextBox6.SetFocus
Exit Sub
End If
SAVEDATA
LOADLIST
LOADCOMBO1
End Sub
Sub SAVEDATANEXT()
Set newrow = tbl1.ListRows.Add
With newrow
For x = 1 To 35
.Range(x) = Me.Controls("TextBox" & x).Text '***************textbox35 contains picture filepath ***********
Next x
.Range(36) = tbl1.ListRows.Count '*********this is important row counter saves the need for search routines***********
End With
End Sub
Sub SAVEDATA()
Set newrow = tbl1.ListRows.Add
With newrow
For x = 1 To 35
.Range(x) = Me.Controls("TextBox" & x).Text '***************textbox35 contains picture filepath ***********
Next x
.Range(36) = tbl1.ListRows.Count '*********this is important row counter saves the need for search routines***********
End With
CLEARFORM
LOADLIST
End Sub
Sub LOADLIST()
Set ws2 = Sheet2
Set tbl1 = ws2.ListObjects("Table1")
With tbl1
If .DataBodyRange.Cells(1, 1) = vbNullString Then Exit Sub
ary = .DataBodyRange
End With
Me.ListBox1.List = ary
End Sub
Private Sub cmdPRINT_Click()
If Me.ComboBox1.Value = vbNullString Then
MsgBox "A PDF cannot be created because no Part # selected.", , "No Part# selected."
Exit Sub
End If
With Sheet3
.Range("A28:O10000").Clear
.Range("D2:D10").Value = ""
.Range("J2:J8").Value = ""
.Range("B17:N17").Value = ""
.Range("B19:N19").Value = ""
.Range("B21:N21").Value = ""
.Range("D23").Value = ""
For Each img In Sheet3.Pictures: img.Delete: Next img '**********clears pictures prior to building new PDF********
ctr = 28
For x = 1 To items - 2
.Range("A15:O26").Copy .Range("A" & ctr)
ctr = ctr + 13
Next x
For y = 2 To 8
.Range("D" & y).Value = Me.ListBox1.List(0, y - 2)
.Range("J" & y).Value = Me.ListBox1.List(0, y - 2 + 7)
.Range("D10").Value = Me.ListBox1.List(0, 14)
Next y
ctr = 0
ctrx = 0
For x = 1 To items - 1
.Cells(17 + ctr, 2).Value = Me.ListBox1.List(ctrx, 15)
.Cells(17 + ctr, 4).Value = Me.ListBox1.List(ctrx, 16)
.Cells(17 + ctr, 6).Value = Me.ListBox1.List(ctrx, 17)
.Cells(17 + ctr, 8).Value = Me.ListBox1.List(ctrx, 18)
.Cells(17 + ctr, 10).Value = Me.ListBox1.List(ctrx, 19)
.Cells(17 + ctr, 12).Value = Me.ListBox1.List(ctrx, 20)
.Cells(17 + ctr, 14).Value = Me.ListBox1.List(ctrx, 21)
.Cells(19 + ctr, 2).Value = Me.ListBox1.List(ctrx, 22)
.Cells(19 + ctr, 4).Value = Me.ListBox1.List(ctrx, 23)
.Cells(19 + ctr, 6).Value = Me.ListBox1.List(ctrx, 24)
.Cells(19 + ctr, 8).Value = Me.ListBox1.List(ctrx, 25)
.Cells(19 + ctr, 10).Value = Me.ListBox1.List(ctrx, 26)
.Cells(19 + ctr, 12).Value = Me.ListBox1.List(ctrx, 27)
.Cells(21 + ctr, 2).Value = Me.ListBox1.List(ctrx, 28)
.Cells(21 + ctr, 6).Value = Me.ListBox1.List(ctrx, 29)
.Cells(21 + ctr, 8).Value = Me.ListBox1.List(ctrx, 30)
.Cells(21 + ctr, 12).Value = Me.ListBox1.List(ctrx, 31)
.Cells(21 + ctr, 14).Value = Me.ListBox1.List(ctrx, 32)
.Cells(23 + ctr, 4).Value = Me.ListBox1.List(ctrx, 33)
'**************************************inserting picture into PDF loader*****************
pFilename = Me.ListBox1.List(ctrx, 34)
If pFilename = "" Then GoTo Err:
Set img = .Pictures.Insert(pFilename)
With img
.Left = Sheet3.Cells(23 + ctr, 14).Left
.Top = Sheet3.Cells(23 + ctr, 14).Top
.Width = 16
.Height = 44.25
.Placement = 1
.PrintObject = True
End With
Err:
'***************************************************************************************
ctrx = ctrx + 1
ctr = ctr + 13
Next x
End With
user = Environ("Username")
FilePath = "C:\Users\" & user & "\Desktop\"
ThisWorkbook.Worksheets("Sheet3").Select
part = Sheet3.Cells(2, 4)
Application.ScreenUpdating = True
'*****************set print area and orientaton********************
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.PrintArea = Sheet3.Range(Sheet3.Cells(1, 1), Sheet3.Cells(ctr, 15))
.Zoom = False
.FitToPagesTall = False
.FitToPagesWide = 1
INSERTBREAK
End With
Application.PrintCommunication = True
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FilePath & "\Part# " & part, OpenAfterPublish:=False, IgnorePrintAreas:=False
'*********************************************************************
Application.ScreenUpdating = True
MsgBox "Data has been exported to PDF on Desktop."
With Sheet3
.Range("A28:O10000").Clear
.Range("D2:D10").Value = ""
.Range("J2:J8").Value = ""
.Range("B17:N17").Value = ""
.Range("B19:N19").Value = ""
.Range("B21:N21").Value = ""
.Range("D23").Value = ""
For Each img In Sheet3.Pictures: img.Delete: Next img '**********clears pictures ready to build new PDF********
End With
End Sub
'********************************open file dialog box to get picture location******************
Private Sub cmdGETPHOTO_Click()
On Error Resume Next
pFilename = Application.GetOpenFilename(FileFilter:="Jpg Files (*.jpg), *.jpg", Title:="SELECT TOOL PHOTO")
Me.Image1.Picture = LoadPicture(pFilename)
Me.TextBox35.Text = pFilename
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub Frame2_Click()
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
If Me.ListBox1.ListIndex = -1 Then Exit Sub
If Me.ListBox1.ListIndex > -1 Then sc = Me.ListBox1.ListIndex
With Me.ListBox1
For x = 1 To 35
Me.Controls("TextBox" & x).Value = .List(sc, x - 1)
Next x
tbl1row = .List(sc, 35)
End With
On Error GoTo Err
Me.Image1.Picture = LoadPicture(Me.TextBox35.Text) 'retrieves picture file location************
Exit Sub
Err: Me.Image1.Picture = LoadPicture("")
End Sub
Private Sub cmdDELETE_Click()
If Me.ListBox1.ListIndex < 0 Then
MsgBox "No Record selected", , "Errors"
Exit Sub
End If
msgValue = MsgBox("ARE YOU CERTAIN YOU WISH TO REMOVE RECORD?", vbCritical + vbYesNo + vbDefaultButton2, "Remove Record")
If msgValue = vbNo Then
CLEARFORM
Exit Sub
End If
tbl1.ListRows(tbl1row).Delete
CLEARFORM
LOADLIST
LOADCOMBO1
MsgBox ("RECORD REMOVED"), vbOKOnly + vbInformation, "Record Removed"
End Sub
Private Sub cmdUPDATE_Click()
If Me.ListBox1.ListIndex < 0 Then
MsgBox "No Record selected", , "Errors"
Exit Sub
End If
With tbl1
For x = 1 To 35
.Range(tbl1row + 1, x) = Me.Controls("TextBox" & x).Text '*********textbox35 contains picture filepath **********
Next x
End With
CLEARFORM
LOADLIST
LOADCOMBO1
End Sub
Private Sub ComboBox1_Change()
With tbl1
r = .ListRows.Count
For t = r To 1 Step -1
.DataBodyRange.Cells(t, 36) = t '******loads range with rowctr prior to spliting with 'FILTER' ***********
Next t
End With
FILTER
items = Me.ListBox1.ListCount
End Sub
Sub FILTER()
ary = tbl1.DataBodyRange
rctr = 1
For j = 1 To UBound(ary)
If ary(j, 1) = Me.ComboBox1.Text Then
rctr = rctr + 1
End If
Next j
ReDim aryx(1 To rctr, 1 To 36)
ctr = 1
For j = 1 To UBound(ary)
If ary(j, 1) = Me.ComboBox1.Text Then
For x = 1 To 36
aryx(ctr, x) = ary(j, x)
Next x
ctr = ctr + 1
End If
Next j
Me.ListBox1.List = aryx
End Sub
Sub LOADCOMBO1()
Set ws2 = Sheet2
Set tbl1 = ws2.ListObjects("Table1")
With tbl1
If .DataBodyRange.Cells(1, 1) = vbNullString Then Exit Sub
ary = .DataBodyRange
End With
Me.ComboBox1.Clear
With CreateObject("Scripting.Dictionary")
For Each rCell In tbl1.ListColumns(1).DataBodyRange
If Not .Exists(rCell.Value) And rCell.Value <> vbNullString Then .Add rCell.Value, Nothing
Next rCell
Me.ComboBox1.List = .keys
.RemoveAll
End With
End Sub
Private Sub UserForm_Initialize()
Set ws2 = Sheet2
Set tbl1 = ws2.ListObjects("Table1")
Me.ListBox1.ColumnCount = 36
s = ""
For x = 1 To 36
s = s & 50 & ";"
Next x
Me.ListBox1.ColumnWidths = s
For x = 1 To 35
Me.Controls("Label" & x).Caption = tbl1.HeaderRowRange(x)
Next x
Me.cmdADD.Enabled = True
Me.TextBox35.Enabled = False
LOADLIST
LOADCOMBO1
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'************ensures workbook is saved if accidently closed**************
If CloseMode = vbFormControlMenu Then
Cancel = False
ThisWorkbook.Save
Unload Me
End If
End Sub
I have tried using various forms of the PageBreak method. I have also tried setting the page layout in various ways, but nothing has worked. I even tried grouping the cells in the "Item" section. I am at a total loss.

My code contains two buttons, but only one button works correctly

First, I want to state, that I am by far no professional, maybe an amateur, so I would really appreciate, if you could give some basic feedback on my coding if you want of course. I think, that would be a good way of learning to code :)
I am a logistics student and I have learned quite a bit of vba coding in class we had last year.
I started as a working student last week and I have to track my hours, so I tried to code a programm in VBA, which
opens an excel worksheet, the user types in the starting day month and year, in the "non-american" way --> 01.09.2022 instead of 09/01/2022.
After that, the vba automatically fills in a table with the dates and the weekdays according to the given date. I added some additional codings like graying out all weekends and stuff.
My problem lies in the buttons. I used two buttons, but only one of them is working.
The button should run the exact same sub it is placed in, to reactivate the code, when the month passed.
Unfortunately somehow, it doesnt recognise the button as a button, I think the macro wont bind to it?
I have a second button, which mutliplies the hours worked with an hour-based salary the user enters, to see how much money was made :)
My code:
Sub Tabelle()
Worksheets.Add
Dim Eingabe As String, T As Integer, Tag As Integer, Z As Long, b As Excel.Shape, Lohn As Double, btn As Excel.Shape
Eingabe = InputBox("Geben Sie bitte das Anfangsdatum des Monats an, z.B. 01.09.2022")
ActiveSheet.Name = "Zeiterfassung " & Eingabe
'Tagesanzahl für eingegebenen Monat finden
If Mid(Eingabe, 4, 2) = "01" Then T = 31
If Mid(Eingabe, 4, 2) = "02" Then T = 29
If Mid(Eingabe, 4, 2) = "03" Then T = 31
If Mid(Eingabe, 4, 2) = "04" Then T = 30
If Mid(Eingabe, 4, 2) = "05" Then T = 31
If Mid(Eingabe, 4, 2) = "06" Then T = 30
If Mid(Eingabe, 4, 2) = "07" Then T = 31
If Mid(Eingabe, 4, 2) = "08" Then T = 31
If Mid(Eingabe, 4, 2) = "09" Then T = 30
If Mid(Eingabe, 4, 2) = "10" Then T = 31
If Mid(Eingabe, 4, 2) = "11" Then T = 30
If Mid(Eingabe, 4, 2) = "12" Then T = 31
'Datum erstellen in Spalte 1
Tag = Left(Eingabe, 2)
For i = 3 To (T + 2)
Cells(i, 1) = Format(Tag, "00") & "." & Mid(Eingabe, 4, 99)
Tag = Tag + 1
Next i
'Wochentage für jedes Datum eintragen in Spalte 2
i = 3
Do While Cells(i, 1) <> ""
If Weekday(Cells(i, 1)) = 1 Then Cells(i, 2) = "Sonntag"
If Weekday(Cells(i, 1)) = 2 Then Cells(i, 2) = "Montag"
If Weekday(Cells(i, 1)) = 3 Then Cells(i, 2) = "Dienstag"
If Weekday(Cells(i, 1)) = 4 Then Cells(i, 2) = "Mittwoch"
If Weekday(Cells(i, 1)) = 5 Then Cells(i, 2) = "Donnerstag"
If Weekday(Cells(i, 1)) = 6 Then Cells(i, 2) = "Freitag"
If Weekday(Cells(i, 1)) = 7 Then Cells(i, 2) = "Samstag"
i = i + 1
Loop
Z = 3
Do While Cells(Z, 2) <> ""
If Cells(Z, 2) = "Samstag" Or Cells(Z, 2) = "Sonntag" Then
Cells(Z, 1).Interior.ColorIndex = 6
Cells(Z, 2).Interior.ColorIndex = 6
Cells(Z, 3).Interior.ColorIndex = 6
Cells(Z, 4).Interior.ColorIndex = 6
Cells(Z, 5).Interior.ColorIndex = 6
Cells(Z, 6).Interior.ColorIndex = 6
End If
Z = Z + 1
Loop
'Code für Stunden gearbeitet
For i = 3 To (T + 2)
Cells(i, 5) = "=" & "(D" & i & "-" & "C" & i & ") * 24"
Next i
'Button für neuen Monat
Set b = ActiveSheet.Shapes.AddFormControl(xlButtonControl, 265, 500, 100, 50)
b.OnAction = "Tabelle"
b.OLEFormat.Object.Text = "Nächster Monat"
Set btn = ActiveSheet.Shapes.AddFormControl(xlButtonControl, 300, 470, 100, 50)
b.OnAction = "Testing"
b.OLEFormat.Object.Text = "Entgelt aktualisieren"
Range("C34").FormulaLocal = "=Summe(E3:E33)-Summe(F3:F33)"
Range("A35") = "Entgelt"
Lohn = InputBox("Geben Sie ihren Stundenlohn ein!")
Range("A40") = "Stundenlohn"
Range("B40") = Format(Lohn, "00.00 €")
Range("A3:F" & T + 2).BorderAround LineStyle:=xlContinuous, Weight:=xlThick
Range("A2:F2").BorderAround LineStyle:=xlContinuous, Weight:=xlThick
Range("A2") = "Datum"
Range("B2") = "Tag"
Range("C2") = "Von"
Range("D2") = "Bis"
Range("E2") = "Std."
Range("F2") = "Pause in Std."
Range("A34") = "Stunden gesamt"
End Sub
Sub Testing()
Range("C35") = Format(Left(Range("C34"), 2) * Range("B40"), "#,#00.00 €")
End Sub
Picture of the Worksheet 1
Picture of the Worksheet 2
The lower button is working btw.
Please, try the next optimized code:
Sub Tabelle()
Dim ws As Worksheet, rngA As Range, rngB As Range, Eingabe As String
Dim minD As Date, maxD As Date, arrD, arrTags, arrCol, rngCol As Range, i As Long
Dim boolYearEnd As Boolean: If Month(Date) = 12 Then boolYearEnd = True
Worksheets.Add
Set ws = ActiveSheet 'set the added sheet
'it proposes the first day of the next month (it ca be easily modified):
Eingabe = InputBox("Geben Sie bitte das Anfangsdatum des Monats an, z.B. 01.09.2022", _
"Date input", Format(DateSerial(IIf(boolYearEnd, Year(Date) + 1, Year(Date)), _
IIf(boolYearEnd, 1, Month(Date) + 1), 1), "dd.mm.yyyy"))
If IsDate(Eingabe) Then
minD = DateValue(Eingabe) ' if a correct input, it is converted to date
Else
MsgBox "The input (" & Eingabe & ") is not a correct date, please enter a correct one in the recommended format...": Exit Sub
End If
maxD = WorksheetFunction.EoMonth(minD, 0) 'set the end of the above month entered
arrD = Evaluate("row(" & CLng(minD) & ":" & CLng(maxD) & ")") 'create an array of the necessary Date
Set rngA = Range("A3").Resize(UBound(arrD), 1) 'set the range where to drop the array content
Application.ScreenUpdating = False: Application.Calculation = xlCalculationManual 'Optimization to make the code faster
With rngA
With .rows(1).Resize(, 6).Offset(-1) 'add headers and format a little:
.Value = Array("Datum", "Tag", "Von", "Bis", "Std.", "Pause in Std.")
.BorderAround LineStyle:=xlContinuous, Weight:=xlThick
.Font.Bold = True
.HorizontalAlignment = xlCenter
.Borders(xlInsideVertical).Weight = xlThick
End With
.Value = arrD
.NumberFormat = "dd.mm.yyyy"
.Offset(, 1).Formula2 = "=TagName(" & .cells(1).Address(0, 0) & ")" 'fill also the days name in the next column
.Offset(, 4).Formula2 = "=(D" & .cells(1).row & "-C" & .cells(1).row & ")*24" 'place the formula to calculate hours difference
.Offset(, 1).Value = .Offset(, 1).Value 'transform formula in value
Set rngB = .Offset(, 1) 'set rngB as next column Offset
End With
arrCol = rngB.Value2 'place B:B column in an array, for faster iteration/processing
For i = 1 To UBound(arrCol)
If arrCol(i, 1) = "Samstag" Or arrCol(i, 1) = "Sonntag" Then
addToRange rngCol, rngB(i).Offset(, -1).Resize(, 6) 'create a Union range to color it at once (very fast)
End If
Next i
If Not rngCol Is Nothing Then rngCol.Interior.ColorIndex = 6
'insert the two necessary buttons:
With ws.Shapes.AddFormControl(xlButtonControl, 270, 500, 100, 50)
.OnAction = "Tabelle": .OLEFormat.Object.Text = "Nächster Monat"
End With
With ws.Shapes.AddFormControl(xlButtonControl, 270, 440, 100, 50)
.OnAction = "Testing": .OLEFormat.Object.Text = "Entgelt aktualisieren"
End With
'add other necessary data:
ws.Range("A35") = "Entgelt"
ws.Range("C34").FormulaLocal = "=Summe(E3:E33)-Summe(F3:F33)"
Dim Lohn As String
Lohn = InputBox("Geben Sie ihren Stundenlohn ein!")
ws.Range("A40").Value = "Stundenlohn"
ws.Range("B40").Value = Format(Lohn, "00.00 €")
With rngA.Resize(, 6) 'a little format for the 6 involved columns
.EntireColumn.AutoFit
.BorderAround LineStyle:=xlContinuous, Weight:=xlThick
.Borders(xlInsideVertical).Weight = xlThin
End With
Application.ScreenUpdating = True: Application.Calculation = xlCalculationAutomatic 'Optimization to make the code faster
MsgBox "Ready..."
End Sub
Function TagName(d As Date) As String 'function to return the day name for a specific date
Dim arrT: arrT = Split("Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", ",")
TagName = arrT(WorksheetFunction.Weekday(d, vbSunday) - 1)
End Function
Private Sub addToRange(rngU As Range, rng As Range) 'function to create the Union range
If rngU Is Nothing Then
Set rngU = rng
Else
Set rngU = Union(rngU, rng)
End If
End Sub

How to compare two values in VBA when a value is bound to vbNewLine in Excel or Access

This is about the structure of a calendar and since I already have too many functions built in, I am not allowed to change the block with vbNewLine , so I need to find a way to solve the problem at this one point:
A function should compare two values and trigger an action in case of a match.
The value myArray(i, 2) ist the Day-Number:
Private Sub InitVariables()
intMonth = Me.cboMonth
intYear = Me.cboYear
lngFirstDayOfMonth = CLng(DateSerial(intYear, intMonth, 1))
intFirstWeekday = getFirstWeekday(lngFirstDayOfMonth)
intDaysInMonth = getDaysInMonth(intMonth, intYear)
End Sub
Private Sub InitArray()
Dim i As Integer
ReDim myArray(0 To 41, 0 To 2)
For i = 0 To 41
myArray(i, 0) = lngFirstDayOfMonth - intFirstWeekday + 1 + i
If Month(myArray(i, 0)) = intMonth Then
myArray(i, 1) = True
myArray(i, 2) = Day(myArray(i, 0))
Else
myArray(i, 1) = False
End If
Next i
End Sub
Private Sub LoadArray()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsFiltered As DAO.Recordset
Dim strsql As String
Dim i As Integer
Dim OrgTime As Date
Dim MyStrTime As String
On Error Resume Next
strsql = "SELECT * from qrytblImVst;"
Set db = CurrentDb
Set rs = db.OpenRecordset(strsql)
If Not rs.BOF And Not rs.EOF Then
For i = LBound(myArray) To UBound(myArray)
If myArray(i, 1) Then
rs.Filter = "[vDate]=" & myArray(i, 0)
Set rsFiltered = rs.OpenRecordset
Do While (Not rsFiltered.EOF)
OrgTime = rsFiltered!vZeit
MyStrTime = Format(OrgTime, "hh:mm")
myArray(i, 2) = myArray(i, 2) & vbNewLine _
& "<div><font color=red> " + MyStrTime + " </div>"
End If
rsFiltered.MoveNext
Loop
End If
Next i
End If
rsFiltered.Close
rs.Close
Set rsFiltered = Nothing
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub PrintArray()
'On Error Resume Next
Dim strCtlName As Variant
Dim strCtlName1 As Variant
Dim i As Integer
Dim lngBlack As Long
Dim lngWhite As Long
lngBlack = RGB(36, 39, 50)
lngWhite = RGB(166, 166, 166)
For i = LBound(myArray) To UBound(myArray)
strCtlName = "TXT" & CStr(i + 1)
Controls(strCtlName).Tag = i
Controls(strCtlName) = ""
Controls(strCtlName) = myArray(i, 2)
If IsNull(Controls(strCtlName)) Then
Controls(strCtlName).Visible = False
Else
Controls(strCtlName).Visible = True
End If
If CStr(Me.cboMonth) = CStr(Month(Date)) And CStr(Me.cboYear) = CStr(Year(Date)) And Len(myArray(i, 2)) <> 0 Then
If Split(myArray(i, 2), vbNewLine)(0) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
Else
Controls(strCtlName).BorderColor = lngWhite
Controls(strCtlName).BorderWidth = 1
End If
strCtlName = "CAL" & CStr(i + 1)
Controls(strCtlName).Tag = i
Controls(strCtlName) = ""
If InStr(myArray(i, 2), "div") Then
Controls(strCtlName) = Left(myArray(i, 2), 2)
Else
Controls(strCtlName) = myArray(i, 2)
End If
If IsNull(Controls(strCtlName)) Then
Controls(strCtlName).Visible = False
Else
Controls(strCtlName).Visible = True
End If
Next i
End Sub
This is how the comparison looks:
If Left(myArray(i, 2), 2) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
I always get a FALSE as a result because vbNewLine changes the day number value in such a way that there is no match.
To check what is causing the problem I added "//" and it looks like this
msgbox Left(myArray(i, 2), 2) & "//"
The result is:
5
//
How can I solve this problem, for all calendar days? Thanks!
Your comparison is looking at the first two characters of the stored value. When the day number is less than 10, the second character will be vbNewLine because the day number is only one digit.
Instead of using Left to capture a fixed number of characters, you can use Split to capture everything to the left of vbNewLine.
If Split(myArray(i, 2), vbNewLine)(0) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
Split will return Error (9) when myArray(i,2) doesn't have a value. You'll need to introduce a check for that case:
If Len(myArray(i,2)) <> 0 Then
If Split(myArray(i, 2), vbNewLine)(0) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
End If

Insert string into a specific line in a text file

I have an excel sheet with strings in the rows.
I have a txt file.
I already have the specific number of lines I want to insert the strings.
but when I use "write" it deletes all and then inserts the string.
How can I insert a string into a specific line in a text file? i'll use a loop to open and close all the txt files.
the code works. just need to put the string in the txt file.
p.s the note is in Hebrew.
Sub SearchTextFile()
'--------------------------------------------------------------------------------------------------úçéìú øéöú ÷åã
Dim Start, Finish, TotalTime As Date
Start = Timer
'--------------------------------------------------------------------------------------------------áéèåì çéùåáéí åòãëåðé îñê åäúøàåú
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
'--------------------------------------------------------------------------------------------------äçæøú çéùåáéí åòãëåðé îñê åäúøàåú
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
'Application.DisplayAlerts = True
'Application.AskToUpdateLinks = True
Dim strLine1, strLine2, strSearch1, strSearch2, Mid1, Mid2 As String
Dim i, j, z, h As Integer
Dim x, LineCount1, LineCount2 As Long
Dim blnFound As Boolean
x = 2
LineCount1 = 0
h = 0
Do Until IsEmpty(Cells(x, 2))
myFileCOMPANY = "L:\" & Cells(x, 2) & "\COMPANY.bat" 'áãé÷ä øàùåðéí äàí îñôø äçáøä ÷ééí áëìì
If Not Dir(myFileCOMPANY) = "" Then 'àí ìà øé÷
strFileName = "L:\" & Cells(x, 2) & "\COMPANY.bat" 'ðúéá - àéôä ìçôù
strSearch1 = Cells(x, 7) 'îä ìçôù
strSearch1 = "If Exist Dfile" & Format(strSearch1, "000") 'ùéðåé ôåøîè
i = FreeFile
On Error Resume Next
Open strFileName For Input As #i
Do While Not EOF(i)
LineCount1 = LineCount1 + 1
Line Input #i, strLine1
If InStr(1, strLine1, strSearch1, vbBinaryCompare) > 0 Then 'äáéã÷ä òöîä äàí äè÷ñè ùîçôùéí ÷ééí áùåøä äæå
strSearch2 = "pz-"
Line Input #i, strLine2
For j = 1 To 4
If InStr(1, strLine2, strSearch2, vbBinaryCompare) + 1 > 0 Then 'äáéã÷ä òöîä äàí äè÷ñè ùîçôùéí ÷ééí áùåøä äæå
Cells(x, 11) = Cells(x, 2) 'îñôø çáøä
Cells(x, 12) = Format(Cells(x, 7), "000") 'îñôø úú
Cells(x, 13) = LineCount1 + j 'îñôø ùåøä
blnFound = True
Cells(x, 14) = Len(strLine2) 'àåøê ùåøä
Cells(x, 15) = "1." & strSearch1 & " 2." & strSearch2 'úå ùàåúå çéôùå
Cells(x, 16) = strLine2 'è÷ñè áùåøä ìôðé
Mid1 = Mid(Cells(x, 16), Cells(x, 14) - 12, 5)
Cells(x, 17) = Cells(x, 16) & " " & Mid1 & Cells(x, 3) & ".pdf"
For z = 1 To 10 'áîéãä åéù òåã îàåúä äçáøä åàåúå äúú àæ ëàï äúåñôåú ëøèéñéí ðöáøéí
If Cells(x, 7) = Cells(x + z, 7) And Cells(x, 2) = Cells(x + z, 2) Then
Cells(x + z, 16) = Cells(x + h, 17)
Mid2 = Mid(Cells(x + z, 16), Cells(x, 14) - 12, 5)
Cells(x + z, 17) = Cells(x + z, 16) & " " & Mid2 & Cells(x + z, 3) & ".pdf"
h = h + 1
End If
Next z
Exit For
End If
Next j
Open myFileCOMPANY For Output As #i
Write #i, "dfgdfg" 'Cells(x + z, 17)
Exit Do
Else: Cells(x, 11) = Cells(x, 2)
Cells(x, 12) = Cells(x, 7)
Cells(x, 15) = "Dfile" & Format(Cells(x, 7), "000") & " not found"
End If
Loop
Close #i
LineCount1 = 0
Else: Cells(x, 11) = "No folder number " & Cells(x, 2)
End If
x = x + h
h = 0
x = x + 1
Loop
'--------------------------------------------------------------------------------------------------äçæøú çéùåáéí åòãëåðé îñê åäúøàåú
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.AskToUpdateLinks = True
'--------------------------------------------------------------------------------------------------æîï ñéåí øéöú ÷åã åçéùåá
Finish = Timer
TotalTime = Format((Finish - Start) / 86400, "hh:mm:ss")
MsgBox ("äãå''ç îåëï" & vbNewLine & "æîï øéöú ÷åã: " & TotalTime)
End Sub
Not sure what code you have tried. It would be easier if you included your code.
You could try using:
If Application.Options.Overtype Then
Application.Options.Overtype = False
End If
If you are trying to add a line to the end of your document you can use the following code:
Function WordAddEnd()
Dim objWord As Object, objDoc As Object, objSelection As Object
Dim endpoint As Integer, moveit As Integer
Dim FileString As String
endpoint = 6
moveit = 0
FileString = "C:\location\folder\document.docx"
Set objWord = CreateObject("Word.Application")
Onerror resumenext
'change error handling
Set objDoc = objWord.documents.Open(FileString)
Set objSelection = objWord.Selection
With objSelection
.EndKey endpoint, moveit
'finds end point of document
.typeparagraph
'goes to next line (like pressing the enter key)
.TypeText ("It's some text you wanted")
'your text here
End With
objWord.documents.Close
End Function
If the document in question is already open, there will be an error so you'll need some error handling in here.

unable to load data into different tabs in Excel 2013 using VB6

In my organization we have one old project/application which was build on Visual Basic 6.0
In that application we have export to Excel "button" where data gets populated into different tabs in spreadsheet with click. It was working very well with Excel 2010 and later until we moved to EXCEL 2013.
Issue: We need data to get exported into 2 tabs in excel 2013 whereas its coming in 1 tab only. I tried using package and deployment wizard and all possible help available. So far no luck. Please let me know if you have any questions or if I am not enough clear. Please find below my code.
Dim uprev As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Dim ExcelWasNotRunning As Boolean ' Flag for final release.
Dim n As Integer
Dim n1 As Integer
Dim n2 As Integer
Dim i As Integer
Dim lastrevdate As String
Dim lastrevrow As Integer
Dim lastrow As Integer
Dim previouspcno As Integer
Dim xlcol As String
Dim j As Integer
Dim k As Integer
Dim dc As Adodc
Dim mrc As Recordset
Dim qpa As New QPArray
Dim Found As Long
Dim StartInd As Long
Dim bFound As Boolean
Dim crlf As String
On Error GoTo errorhandler1
crlf = Chr(13) & Chr(10)
ReDim qs(10) As String
ReDim q(10) As Integer
ReDim hdr(15) As Integer
ReDim rev(10, 0) As String
ReDim part(0) As String
ReDim sl(nof) As String
ReDim cmpsql2(0) As String
ReDim deletedfromsql(3, 0) As String
Dim doThis As Integer
Dim iReturn As Integer
Dim revlev As String
Dim Date_Engr As String
Dim Date_Checker As String
'On Error Resume Next ' Defer error trapping.
'Removed, not checking to see if excel is open properly
'Bert - 6/5/07
'Set xlApp = GetObject(, "Excel.Application")
'If Err.Number <> 0 Then
' ExcelWasNotRunning = True
'Else
' MsgBox ("Please Close Excel before continuing")
' Exit Sub
'End If
Err.Clear ' Clear Err object in case error occurred.
iReturn = MsgBox("Please Close ALL Excel applications before continuing", vbOKOnly, "WARNING")
ExcelWasNotRunning = True
'fixwidth
Screen.MousePointer = vbHourglass
'DetectExcel
Set xlApp = Excel.Application
'path(8) = "C:\SwitchGear\Files1\eng_prod\Jobs\cs01157\medt\"
If Dir(Defaults.medt & "\" & cs & sos & "mbom.xls", vbNormal) <> "" Then
mbomflag = 1
FileCopy Defaults.medt & "\" & cs & sos & "mbom.xls", Defaults.medt & "\" & cs & sos & "mbom.bak"
Set xlBook = GetObject(Defaults.medt & "\" & cs & sos & "mbom.xls")
Set xlSheet = xlBook.Worksheets(1)
Set xlsheet2 = xlBook.Worksheets(2)
Do
qs(1) = "1. Do not list changes on rev sheet" & crlf
qs(1) = qs(1) & "2. list changes on rev sheet but do not increase rev level" & crlf
qs(1) = qs(1) & "3. list changes on rev sheet and increase rev level"
qs(0) = InputBox(qs(1))
If qs(0) = "" Then Exit Sub
Loop Until qs(0) > "0" And qs(0) < "4"
If qs(0) = "3" Then ' up the revision
uprev = 2
revlev = xlsheet2.Cells(5, 3) + 1
Date_Engr = Date
Date_Checker = Date
Else
uprev = 1
revlev = xlsheet2.Cells(5, 3)
Date_Engr = xlSheet.Cells(16, 2) ' get the old rev number
Date_Checker = xlSheet.Cells(16, 3)
End If
lastrow = xlSheet.Cells.Range("E20").End(xlDown).Row
ReDim cmpxl2(0) As String
ReDim cmpxl3(0) As String
ReDim cmpxl4(0) As String
n = 0
For i = 20 To lastrow
If xlSheet.Cells(i, 2) <> "" Then
n = n + 1
ReDim Preserve cmpxl2(n) As String
ReDim Preserve cmpxl3(n) As String
ReDim Preserve cmpxl4(n) As String
cmpxl2(n) = xlSheet.Cells(i, 2) & " " & Format(i)
cmpxl3(n) = xlSheet.Cells(i, 3)
cmpxl4(n) = xlSheet.Cells(i, 4)
End If
Next i
n1records = Adodc1.Recordset.RecordCount
'If n > n1records Then 'it's been deleted from sql so find the part and add to xl revision sheet
n1 = 0
ReDim cmpsql2(n1records) As String
With Adodc1.Recordset
For i = 1 To n1records
If i = 1 Then
Adodc1.Recordset.MoveFirst
Else
Adodc1.Recordset.MoveNext
End If
cmpsql2(i) = !pcno
Next i
End With
For i = 1 To n
bFound = qpa.Find(cmpsql2(), Left$(cmpxl2(i), 4), Found, , 1)
If bFound = False Then
q(1) = Val(Mid$(cmpxl2(i), 6))
n1 = n1 + 1
ReDim Preserve deletedfromsql(3, n1)
deletedfromsql(1, n1) = xlSheet.Cells(q(1), 2)
deletedfromsql(2, n1) = xlSheet.Cells(q(1), 3)
deletedfromsql(3, n1) = xlSheet.Cells(q(1), 4)
End If
Next i
'End If
n = 0
Do
n = n + 1
If xlsheet2.Cells(n + 13, 1) > " " Then
ReDim Preserve rev(10, n)
ReDim Preserve part(n)
'part(n) = xlSheet.Cells(n + 13, 3) & "*" & xlSheet.Cells(n + 13, 1)
If xlsheet2.Cells(n + 13, > CDate(lastrevdate) Then
lastrevdate = xlsheet2.Cells(n + 13, 8-)
End If
For i = 1 To 10
rev(i, n) = xlsheet2.Cells(n + 13, i)
Next i
Else
Exit Do
End If
Loop
If engr = "" Then
engr = xlSheet.Cells(14, 2)
chcked = xlSheet.Cells(14, 3)
End If
Else
mbomflag = 0
revlev = 0
If engr = "" Then
engr = UCase$(InputBox("Enter Mechanical drafter's Initials:", "Enter Initials"))
'If engr = "" Then Exit Sub
chcked = UCase$(InputBox("Enter Checker's Initials:", "Enter Initials"))
'If chcked = "" Then Exit Sub
End If
End If
'Set xlBook = GetObject(path(2) & "vb\sql\ebomtemplate.xls")
Set xlBook = GetObject(Defaults.ApplicationPath & "\mbomTemplate.xls")
Set xlSheet = xlBook.Worksheets(1)
Set xlsheet2 = xlBook.Worksheets(2)
If revlev = 0 Then
xlsheet2.Cells(14, 8= Date
End If
'xlSheet.PageSetup.Zoom = 50
If UBound(rev, 2) > 0 Then
lastrevrow = UBound(rev, 2) + 13
For i = 14 To UBound(rev, 2) + 13
For j = 1 To 10
xlsheet2.Cells(i, j) = rev(j, i - 13)
Next j
Next i
Else
lastrevrow = 13
End If
'If uprev = 1 Then
' xlBook.Application.Visible = True
' xlBook.Parent.Windows(2).Visible = True
' xlBook.Parent.Windows(2).Activate
' xlSheet.Activate
'bFound = bringwindowtotop(hwnd)
'xlBook.Sheets(1).Select
'ActiveSheet.Visible = True
'xlBook.Application.DoubleClick
'Else
xlBook.Application.Visible = True
xlBook.Parent.Windows(1).Visible = True
xlBook.Parent.Windows(1).Activate
xlSheet.Activate
'DetectExcel
'bFound = bringwindowtotop(hwnd)
'End If
'DetectVB
'Found = apiShowWindow(hwnd, SW_SHOWMINIMIZED)
'DetectExcel
'Found = apiShowWindow(hwnd, SW_SHOWMAXIMIZED)
Me.Visible = False
Screen.MousePointer = vbDefault
'If uprev = 1 Then
' xlBook.NewWindow.Activate
' With xlBook.NewWindow
' .ActiveSheet = 2
' .Zoom = 50
' End With
'End If
'xlBook.Application.Visible = True
'xlBook.Parent.Windows(1).Visible = True
'xlSheet.Activate
'qs(1) = "03040609121314151617181920212223242526272829303132333435"
cs = UCase$(cs)
sos = UCase$(sos)
xlSheet.Cells(10, 2) = cs & Left$(sos, 5)
If Val(framestr(0, 0, 15)) < 8 Then qs(1) = "2" Else qs(1) = "4"
xlSheet.Cells(10, 3) = "-" & Mid$(sos, 6, 1) & Right$(sos, 1) & "B" & qs(1) & "004"
xlSheet.Cells(12, 2) = Right$(sos, 3)
xlSheet.Cells(10, 6) = framestr(0, 0, 3)
'xlSheet.Cells(12, 3) = "0"
'xlSheet.Cells(16, 2) = Date
'xlSheet.Cells(16, 3) = Date
xlSheet.Cells(10, 4) = framestr(0, 0, 658) 'sold to
xlSheet.Cells(11, 4) = framestr(0, 0, 657)
xlSheet.Cells(12, 4) = framestr(0, 0, 656)
xlSheet.Cells(14, 2) = engr
xlSheet.Cells(14, 3) = chcked
xlSheet.Cells(14, 4) = framestr(0, 0, 655) 'for
xlSheet.Cells(14, 6) = framestr(0, 0, 661) 'purchase order
xlSheet.Cells(15, 4) = framestr(0, 0, 654)
xlSheet.Cells(16, 4) = framestr(0, 0, 653)
xlcol = "L M N O P Q R S T U V W X Y Z AAABACADAEAFAGAHAIAJ"
qs(1) = "L12:" & Trim$(Mid$(xlcol, (nof + 1) * 2 - 1, 2)) & "16"
xlSheet.Cells.Range(qs(1)).Value = " "
For i = 1 To nof
xlSheet.Cells(19, i + 11) = i
Next i
For i = 1 To nof + 1
qs(1) = Trim$(Mid$(xlcol, i * 2 - 1, 2)) & "12:" & Trim$(Mid$(xlcol, i * 2 - 1, 2)) & "16"
With xlSheet.Cells.Range(qs(1)).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
Next i
qs(1) = Chr(76) & "12:" & Trim$(Mid$(xlcol, nof * 2 - 1, 2)) & "12"
With xlSheet.Cells.Range(qs(1)).Borders(xlTop)
'.LineStyle = xlContinuous
.Weight = xlMedium
End With
qs(1) = Chr(76) & "16:" & Trim$(Mid$(xlcol, nof * 2 - 1, 2)) & "16"
With xlSheet.Cells.Range(qs(1)).Borders(xlBottom)
'.LineStyle = xlContinuous
.Weight
I am aware VB 6 is outdated and not sure why they don't move to VB.NET. I would really appreciate if anyone can help. Thanks in advance :)
Your problem is nothing to do with VB6 being outdated. The problem is that this code is unrunnable. I can only make a guess that this is some hacked version based on the real running code. I will make some guesses based on approximately what this code should really look like. However, it would be a good idea to provide the actual code.
By "tabs", I take it you mean "worksheets". I am guessing that they are called "Sheet1" and "Sheet2". So basically, only "Sheet1" is actually getting re-populated. "Sheet2" remains as it previously looked.
I would suggest that you put a breakpoint on the line:
Set xlsheet2 = xlBook.Worksheets(2)
See whether xlsheet2.Cells(14,8) evaluates to the date you expect to see on that worksheet.
After stepping through this line, ensure that xlsheet2 actually points to the worksheet you expect it to. I would also put breakpoints on every line which reads or writes xlsheet2.Cells(x,y) evaluate it, and look at sheet2, ensuring that the value read or written back is correct.

Resources