This is driving me in F****** insane, I've tired so many idea and still nothing after two bloody days. I'm going to jump out the window and give up.
Posts by RBLearning
-
-
Hi all, I have the code below but the only thing that's not working is the image file (the image is placed in cell 45), this isn't transferring to word. Can anyone shed any light as to what I'm doing wrong? Thanks in advance.
Code
Display MorePrivate Sub PrintUserBtn_Click() Dim numberOfStaff As Long numberOfStaff = Me.lbResList.ListCount 'CountItems If numberOfStaff = 0 Then Exit Sub Dim wdApp As Object, wdDoc As Object, x Set wdApp = CreateObject("Word.Application") Set wdDoc = wdApp.Documents.Open("I:\Details.docx") wdApp.Visible = True With wdDoc.Content.Find .Execute FindText:="AAA", ReplaceWith:=Me.lbResList.List(0, 4), Replace:=wdReplaceAll 'Title .Execute FindText:="BBB", ReplaceWith:=Me.lbResList.List(0, 1), Replace:=wdReplaceAll 'First Name .Execute FindText:="ccc", ReplaceWith:=Me.lbResList.List(0, 5), Replace:=wdReplaceAll 'Surname .Execute FindText:="ddd", ReplaceWith:=Format(DateofBirth, "DD/MM/YYYY"), Replace:=wdReplaceAll 'Date of Birth .Execute FindText:="eee", ReplaceWith:=Me.lbResList.List(0, 7), Replace:=wdReplaceAll 'Email .Execute FindText:="fff", ReplaceWith:=Format(EnrolmentDate, "DD/MM/YYYY"), Replace:=wdReplaceAll 'Register Date .Execute FindText:="ggg", ReplaceWith:=Me.lbResList.List(0, 37), Replace:=wdReplaceAll 'Mailing List .Execute FindText:="hhh", ReplaceWith:=Me.lbResList.List(0, 36), Replace:=wdReplaceAll 'Notes .Execute FindText:="iii", ReplaceWith:=Me.lbResList.List(0, 45), Replace:=wdReplaceAll 'Image End With wdApp.DisplayAlerts = False x = "\" & StaffName.Value & " Details.docx" 'wdDoc.SaveAs (x) Set wdApp = Nothing: Set wdDoc = Nothing End Sub
-
Still no luck, any suggestions please?
-
Hi all,
I've been working on a new userform and so far everything works out great apart from one thing. I just can't figure out how to count how many users are attending an event and send this to a word document.
I select from a combobox a date of an event, a populated list displays (all working great) the list of guests. I then click (AttendPrintBtn) a button to print out the attendance sheet using the code below, but I just figure out the code to show how many users (brain freeze) are attending at the bottom, can someone be kind enough to help me out please?
I'm using a comboboxes next to their name (data taken from a 'User' sheet) for me (cboAttend1 through to cboAttend5) to select if the guest have attended or not, if the guest attended then I select a forward slash / to show or A for absent - cboAttend1 = week 1, cboAttend2 = week 2, through to cboAttend5 for week 5.
Here's praying - thanks in advance
Code
Display MorePrivate Sub AttendPrintBtn_Click() Dim numberOfStaff As Long numberOfStaff = Me.lbResList.ListCount 'CountItems If numberOfStaff = 0 Then Exit Sub Dim wdApp As Object, wdDoc As Object, x Set wdApp = CreateObject("Word.Application") Set wdDoc = wdApp.Documents.Open("Register.docx") wdApp.Visible = True With wdDoc.Content.Find 'Table 3 - Dates of event. .Execute FindText:="Bbb", ReplaceWith:=Format(StartDate, "DDDD"), Replace:=wdReplaceAll .Execute FindText:="Ccc", ReplaceWith:=Format(Reminder1, "DD/MM/YY"), Replace:=wdReplaceAll .Execute FindText:="Ddd", ReplaceWith:=Format(Reminder2, "DD/MM/YY"), Replace:=wdReplaceAll .Execute FindText:="Eee", ReplaceWith:=Format(Reminder3, "DD/MM/YY"), Replace:=wdReplaceAll .Execute FindText:="Fff", ReplaceWith:=Format(Reminder4, "DD/MM/YY"), Replace:=wdReplaceAll .Execute FindText:="Ggg", ReplaceWith:=Format(Reminder5, "DD/MM/YY"), Replace:=wdReplaceAll End With Dim y, z For y = 0 To numberOfStaff - 1 If y > 9 Then wdDoc.Tables(3).Rows.Add wdDoc.Tables(3).Cell(y + 3, 2).Range.Text = y + 1 End If 'wdDoc.Tables(4).Cell(y + 1, 3).Range.Text = Me.lbResList.List(y, 1) 'Table 1 - Event Name. wdDoc.Tables(1).Cell(y + 3, 2).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 3).Value 'Table 2 - Event Location, day and times. wdDoc.Tables(2).Cell(y + 1, 2).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 28).Value wdDoc.Tables(2).Cell(y + 1, 6).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 11).Value wdDoc.Tables(2).Cell(y + 1, 8).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 12).Value wdDoc.Tables(2).Cell(y + 1, 10).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 2).Value 'Table 3 - Register, late, on time etc. wdDoc.Tables(3).Cell(y + 1, 5).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 19).Value wdDoc.Tables(3).Cell(y + 1, 6).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 20).Value wdDoc.Tables(3).Cell(y + 1, 7).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 21).Value wdDoc.Tables(3).Cell(y + 1, 8).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 22).Value wdDoc.Tables(3).Cell(y + 1, 9).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 23).Value 'Table 4 - Name, surname and attendance results wdDoc.Tables(4).Cell(y + 1, 3).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 5).Value wdDoc.Tables(4).Cell(y + 1, 4).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 1).Value wdDoc.Tables(4).Cell(y + 1, 5).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 14).Value wdDoc.Tables(4).Cell(y + 1, 6).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 15).Value wdDoc.Tables(4).Cell(y + 1, 7).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 16).Value wdDoc.Tables(4).Cell(y + 1, 8).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 17).Value wdDoc.Tables(4).Cell(y + 1, 9).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 18).Value 'Table 5 - Code NEEDED below to display how many attendees to the event - replace 31 through to 35) 'wdDoc.Tables(5).Cell(y + 1, 1).Range.Text = Me.lbResList.List(y, 1) 'wdDoc.Tables(5).Cell(y + 1, 2).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 31).Value 'wdDoc.Tables(5).Cell(y + 1, 3).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 32).Value 'wdDoc.Tables(5).Cell(y + 1, 4).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 33).Value 'wdDoc.Tables(5).Cell(y + 1, 5).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 34).Value 'wdDoc.Tables(5).Cell(y + 1, 6).Range.Text = Sheets("Users").Cells(Me.lbResList.List(y, 0), 35).Value Next y wdApp.DisplayAlerts = False x = "" & Format(Date, "DDMMYYYY") & " Register.docx" 'wdDoc.SaveAs (x) Set wdApp = Nothing: Set wdDoc = Nothing End Sub
-
Hi all, can someone be kind enough to help me out here please? I have the following code below where the combobox lists dates from a column from my users sheet. All works well (apart from the dates are over the place and not in order) but I just can't seem to stop the duplicate dates showing in the drop down (I can't change the user sheet as data in there is required), does anyone know how to stop the duplicates and put it in date order? Thanks in advance.
[VBA]Private Sub UserForm_Initialize()
SortStartDateRange
Dim ws As Worksheet
Dim v
Dim n As Long
Set ws = Worksheets("Users")
v = ws.Range("K2:K500").value
For n = LBound(v) To UBound(v)
v(n, 1) = Format(v(n, 1), "dd/mm/yyyy")
Next
Me.OutListCombo.List = v
SortStartDateRange
End Sub[/VBA] -
Hi all,
I'm sure this is somewhere in the forum but after looking I can't find the correct information, I'm trying to populate a list into a listbox (called OutListBox) in a form.
I have a column 'A' for the names and column 'O' for the responses. In the 'O' column I have 'Yes' or 'No', this shows me if the user has responded to a question.
So what I'm trying to achieve is to have the following in the OutListBox: Display name and only display those who haven't replied.
Then an ability to click on the name and send an email to the user. I have the following script but the dates are all wrong. Can someone be kind enough to check and correct my mistakes?
[VBA]Private Sub UserForm_Initialize()
OutListBox.Clear
Dim ws As Worksheet
Set ws = Worksheets("Users")Dim x As Integer, y As Integer, i As Integer
y = ws.Cells(5000, 8).End(xlUp).row + 1
i = 2
For x = 2 To y
With OutListBox
.ColumnCount = 4
.ColumnWidths = "20;100;100;90"
'If we need to search all 4 date columns =
'If Format(StartDate.Value, "DD/MM/YYYY") = Format(ws.Cells(x, 7).Value, "DD/MM/YYYY") or Format(StartDate.Value, "DD/MM/YYYY") = Format(ws.Cells(x, 8).Value, "DD/MM/YYYY") or Format(StartDate.Value, "DD/MM/YYYY") = Format(ws.Cells(x, 10).Value, "DD/MM/YYYY") or Format(StartDate.Value, "DD/MM/YYYY") = Format(ws.Cells(x, 11).Value, "DD/MM/YYYY") Then
'.AddItem
'.List(x - 2, 1) = Sheets("Users").Cells(x, 1).Value
'End If
If Format(OutListBox.Value, "DD/MM/YYYY") = Format(ws.Cells(x, 7).Value, "DD/MM/YYYY") Then
.AddItem
.List(i - 2, 1) = Sheets("Users").Cells(x, 1).Value
.List(i - 2, 0) = x
.List(i - 2, 2) = Sheets("Users").Cells(x, 8).Value
.List(i - 2, 3) = Sheets("Users").Cells(x, 15).Value
i = i + 1
End If
End WithNext x
End Sub[/VBA]
-
Hiya,
I've looked in the properties for the multiform but I can't see anywhere the feature to change the scrollbar colour; could someone please point me in the right direction?
If this can't be done can a simple VBA script do this?
Thanks in advance.
-
Re: Date below set date not Valid entry
Not to worry KJ, I've figured it out, code for others.
Code
Display MorePrivate Sub StaffStartDate_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) If IsDate(StaffStartDate.Value) = False Then MsgBox "Invalid date, please re-enter", vbCritical StaffStartDate.Value = "" StaffStartDate.BackColor = RGB(255, 185, 185) Exit Sub End If Dim a As Date, b As Date a = StaffStartDate.Value b = "01/08/2017" Dim dDate As Date If a < b Then MsgBox "Invalid Date, Please enter a date on or after 01/08/2017", vbCritical StaffStartDate.Value = "" StaffStartDate.BackColor = RGB(255, 185, 185) Exit Sub End If StaffStartDate.Value = Format(StaffStartDate.Value, "DD/MM/YYYY") End Sub
-
Re: Word - Find Text and Replace Error
Thank you, for the updated code and the tip. Textfields and combos changed to suit.
Working great.
-
Re: Date below set date not Valid entry
That's what I'm trying to figure out lol.
-
I have a textbox called StartDate (inside a userform) where I enter a date of when a user joins, what I would like is that when I enter a date dd/mm/yyyy it checks to see if I've entered the month and the year (2017) above a certain time frame.
For example:
If I enter 01/08/2017 this is allowed (or any date after that date).
If I enter 02/07/2017 a message will display that the date is not valid (or any date below that range, so if press 2016 instead of 2017).
Is there a simple way of doing this please?
-
Re: Word - Find Text and Replace Error
Thanks Carim, yes I've tried that I keep getting compile error!
-
Hi all, I hope someone can help me? I have the following code and I just can't seem to get the textbox (Name) and combobox (cbolocation) values to transfer to word, the StartDate works perfectly.
Could someone please point me in the right direction as to what I'm doing wrong? Thanks in advance.
Code
Display MorePrivate Sub AttendPrintBtn_Click() Dim wdApp As Object, wdDoc As Object, x Set wdApp = CreateObject("Word.Application") Set wdDoc = wdApp.Documents.Open("Desktop\register.docx") wdApp.Visible = True With wdDoc.Content.Find .Execute FindText:="Vvv", ReplaceWith:=Name, Replace:=wdReplaceAll .Execute FindText:="Xxx", ReplaceWith:=Format(StartDate, "DDDD DD MMMM YYYY"), Replace:=wdReplaceAll .Execute FindText:="Zzz", ReplaceWith:=cboLocation, Replace:=wdReplaceAll End With wdApp.DisplayAlerts = False x = "Desktop\" & Format(Date, "YYYYMMMDD") & " register.docx" wdDoc.SaveAs (x) Set wdApp = Nothing: Set wdDoc = Nothing End Sub
-
Re: ComboBox Date Format not working
I'm using this code and it's working perfectly (thanks for your help) but is there a way to modify the code if a different value is selected?
Code
Display MorePrivate Sub cboDate_Change() On Error Resume Next Dim i As Integer, Mnths, dt As Date dt = cboDate.Value Mnths = Array(1, 3, 6) '// These are the number of months to add. For i = 0 To 2 Me.Controls("Reminder" & Mnths(i)) = DateAdd("m", Mnths(i), dt) Me.cboDate.Value = Format(Me.cboDate.Value, "dd/mm/yyyy") Me.Reminder1.Value = Format(Me.Reminder1.Value, "dd/mm/yyyy") Me.Reminder3.Value = Format(Me.Reminder3.Value, "dd/mm/yyyy") Me.Reminder6.Value = Format(Me.Reminder6.Value, "dd/mm/yyyy") Next If Len(cboDate) > 0 Then cboDate.BackColor = RGB(255, 255, 255) End If End Sub
What I would like to do is, if I select the value 'None assigned' from the combox 'cboDate' the calculation won't add the dates to the 'Reminder 1,3 & 6' textboxes; is this possible?
Thank you in advance.
-
Re: Search working but not correct!
Good idea, thanks.
-
Re: Is this Possible - Select ComboBox value, the give answer
Thanks, I'm playing around.
-
Re: Search working but not correct!
No merged cells. I'm still learning VBA and copied the code from elsewhere and playing around. Would you be kind enough to point me in the right direction as what to change?
Thanks.
-
I have the following coding to search for a user, everything works OK but I can't seem to get the results that I want displayed right.
This is what I'm doing:
Select date from a drop down list and press search - workingHave the results show me the name (column a), location (column g) and the tutor (column h) from a sheet called 'Users'.
The results come back with:
Name (column a) department (column b) and job title (column c).Can someone enlighten me as to what I'm doing wrong please?
Code
Display MorePrivate Sub UserForm_Initialize() Dim ws As Worksheet Dim v Dim n As Long Set ws = Worksheets("Data") v = ws.Range("PassportDate").Value For n = LBound(v) To UBound(v) v(n, 1) = Format(v(n, 1), "dd/mm/yyyy") Next Me.cboDateSearch.List = v End Sub Private Sub AttendClearBtn_Click() Application.ScreenUpdating = False Unload AttendeeForm AttendeeForm.Show Application.ScreenUpdating = True End Sub Private Sub AttendSearchBtn_Click() On Error Resume Next Dim shCurrent As Worksheet Dim shResults As Worksheet Dim found As Range Dim firstFound As String Dim SrchCol_1 As String Dim SrchCol_2 As String Dim r As Long If cboDateSearch = "" And tbSrch2 = "" Then Exit Sub Set shData = Sheets("Users") 'change to suit Set rgData = shData.Cells.CurrentRegion Set rgData = rgData.Offset(1, 0).Resize(rgData.Rows.Count - 1, rgData.Columns.Count) Set shCurrent = ActiveSheet Application.ScreenUpdating = False Application.DisplayAlerts = False On Error Resume Next Sheets("Results").Delete On Error GoTo 0 Application.DisplayAlerts = True Sheets.Add after:=Sheets(Sheets.Count) ActiveSheet.Name = "Results" Set shResults = Sheets("Results") With shResults .Cells(1, 1) = "ID" .Cells(1, 2) = "Staff Name" 'change to suit .Cells(1, 7) = "Location" .Cells(1, 8) = "Tutor" End With 'columns to search thru - change to suit SrchCol_1 = "F" SrchCol_2 = "F" lbResList.ListIndex = -1 StaffName = "" cboLocation = "" cboTutorsName = "" r = 1 If cboDateSearch <> "" Then With rgData.Columns(SrchCol_1) Set found = .Find(cboDateSearch, rgData.Cells(rgData.Rows.Count, SrchCol_1)) If Not found Is Nothing Then firstFound = found.Address Do r = r + 1 found.EntireRow.Copy shResults.Cells(r, 1) shResults.Cells(r, 1).Insert Shift:=xlToRight shResults.Cells(r, 1) = found.Row Set found = .FindNext(found) Loop While Not found Is Nothing And found.Address <> firstFound End If End With End If If tbSrch2 <> "" Then With rgData.Columns(SrchCol_2) Set found = .Find(tbSrch2, rgData.Cells(rgData.Rows.Count, SrchCol_2)) If Not found Is Nothing Then firstFound = found.Address Do r = r + 1 found.EntireRow.Copy shResults.Cells(r, 1) shResults.Cells(r, 1).Insert Shift:=xlToRight shResults.Cells(r, 1) = found.Row Set found = .FindNext(found) Loop While Not found Is Nothing And found.Address <> firstFound End If End With End If If r = 1 Then lbResList.RowSource = "" MsgBox "There is no one booked for that date." Else Set rgResults = shResults.Cells.CurrentRegion Set rgResults = rgResults.Offset(1, 0).Resize(rgResults.Rows.Count - 1, rgResults.Columns.Count) rgResults.RemoveDuplicates Columns:=Array(1), Header:=xlNo Set rgResults = shResults.Cells.CurrentRegion Set rgResults = rgResults.Offset(1, 0).Resize(rgResults.Rows.Count - 1, rgResults.Columns.Count) ActiveWorkbook.Names.Add Name:="rgResults", RefersTo:=rgResults lbResList.RowSource = "rgResults" End If shCurrent.Activate Application.ScreenUpdating = True End Sub Private Sub AttendCloseBtn_Click() Unload Me End Sub
Thank you in advance.
-
Hi all,
Just a thought, I'm not sure if this is possible and I've been trying to figure out how this could work. My idea is to select a given date from a comboBox, once selected the database will automatically give me a location where to attend.
For example
ComboBox date (dates are from a separate sheet populated).
10/09/2017
11/09/2017
12/09/2017
13/09/2017A text box will then show me the location (that has already been booked for that date), yet again populated from a list.
Date Selected: 10/09/2017
Location: Room 21I'm not sure how this could work, any thoughts (I'm not after any scripting, just a concept how it could work)?
-
Re: ComboBox Date Format not working
Thanks so much, works perfect.