Opening a vba-created calendar from another userform? - excel

In 64-bit MS Office there is no more Date-Picker.
I have found a VBA-created calendar, consisting of of a class and a userform.
Original Page
English Translation of Page
I have imported the elements into my Excel file.
How could I open the calendar from my Userform2? My Userform2 has a field for date value. A call the Userform with a button then how could I call the calendar from my Userform2?
I am quite a beginner in VBA, I would prefer a detailed answer :)

Regional issue with the control
Although handy, this control will generate errors for those trying to use it outside of Germany (and possibly even within Germany) since it's hard-coded to rely on a date format of "dd.mm.yyyy" — which hasn't been an official date standard standard anywhere (including Germany) since 1996.
To fix the issue, replace each of the four offending lines with the below alternatives, which instead use the DateSerial function as an "international date handling solution". (The quickest way to locate them in frmCalendar is to search the project for "01.".)
intDayCounter = Weekday(DateSerial(dYear, dMonth, 1), vbMonday)
datLastDayMonth = fLastDayInMonth(DateSerial(dYear, dMonth, 1))
Me.Controls(strLabel).Caption = Mid(fLastDayInMonth(_
DateSerial(dYear, dMonth - 1, 1)), 1, 2) - intVormonat
Me.Controls(strLabel).Caption = Mid(fLastDayInMonth(_
DateSerial(dYear - 1, dMonth + 11, 1)), 1, 2) - intVormonat
Using the control is a userform
To add this custom control with on your userform:
Add a command button to your user form
Right-click the new button and click View Code
Paste the code below into the _Click() procedure for your button
frmCalendar.Show
TextBox1 = g_datCalendarDate
...where TextBox1 is the name of the control where you want the selected date.
Clicking the button will now open the calendar, allow the user to select a date, close the calendar, and populate the specified control with the selected date.

If the calendar is contained within a userform, find the name of that userform, then add a command button to Userform2 and use code similar to:
Private Sub CommandButton1_Click()
dateUserfom.Show
End Sub

Related

Manual date selection in vba

I am trying to find a way to allow a manual date + time. I have a worksheet that has a button for which when the user updates the table, they click the button and it inputs the current date and time. The challenges is I currently have the Now() function and every time I open the workbook, the date gets updated based on the now date. I want this to be a manual action.
I've searched here and on the internet, and all I can find is the automated NOW() or others that seem to automate the process.
You can use VBA to write the current date (plus time) into a cell on a button click:
Public Sub MyButton_Click()
Worksheets("Sheet1").Range("A1").Value = Now
End Sub
Just link that procedure with a button and it will write the date+time into A1 every time you click the button.

VBA - How to retrieve value from one TextBox and make it appear in another?

I have Userform in Excel.
The first tab of the multipage has a variable called Staffwage_TextBox. Someone is expected to enter a value.
I want to retrieve this value and make it appear on the next multipage in a TextBox called staffwage.
I have this code so far:
Private Sub staffwage_Change()
Dim trial As String
Staffwage_TextBox.Characters.Text
staffwage = Staffwage_TextBox.Value
trial = Staffwage_TextBox.Characters.Text
End Sub
Any help would be appreciated,
Thank you :)
If I got you right, You have a multipage and tab 1 and 2 hold a textbox and if something is entered in the first textbox, you want it to appear also in the second one.
First things first: Elements within the multipage are treated like there is no multipage. So it doesn't matter where they are.
While I'm confused by: ...a variable called Staffwage_TextBox.... I'm sure that is an object.
To make it as easy as possible I will use different names.
I created a multipage and added a textbox at both pages. Named TextBox1 (at page 1) and TextBox2 (at page 2). Now I double click TextBox1 and get moved to the sub for a change event (looks like you are at this point). Now I simply put in there:
TextBox2.Value = TextBox1.Value
And that is all. If i now put anything in the first text box, then the second one will have the same text. (Only works in that direction)

I cannot identify the 'VBA.Date' code component

I have found many blocks of code that containVBA.Date, for example;
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
Target.Offset(0, 1).Value = Format(VBA.Date, “MM/DD/YYYY”)
End Sub
Or
Sub YearSheets()
Dim i As Integer
i = 0
Do
Sheets.Add(After:=Sheets(Sheets.Count)).Name = Format(VBA.Date + i, “MM-DD-YYYY”)
i = i + 1
Loop Until i = 365
End Sub
I have tried these steps:
I have pushed F1 for VBA's help but it shows "Keyword Not Found".
Searched my VBA books but no one shows something because they take such a piece of information as unimportant or too easy (I guess).
I have tried to Google it --> You can imagine what happens with a combination of such common words.
I have pushed F2 in the VBE Window and opened the Object Browser
i. I searched for VBA and I got the library ... not very bright
ii. I searched for the Date Property and I found it to be preceded by the DateTime Module and going more in seniority from the VBA Library.
Question-born-from-question: Is it possible to be the VBA library here VBA.Date?
Frustrating-thing-that-happens: Once I type VBE IntelliSense shows Date Property, so it's hard-coded somewhere in my machine.
What really is VBA.Date - an object, a library that can be entered as as object?
Date() and Time() are Properties of the DateTime Class. Found in Excel VBA. They are of DataType Variant that contain the current system date when Date is used and current system time when Time is used.
They do not need to be preceeded by the VBA or the DateTime in order to be used they can simply be used with the terms Date, and Time.
Date, and if the calendar is Gregorian, Date$ behavior is unchanged by the Calendar property setting. If the calendar is Hijri, Date$ returns a 10-character string of the form mm-dd-yyyy, where mm (01-12), dd (01-30) and yyyy (1400-1523) are the Hijri month, day and year. The equivalent Gregorian range is Jan 1, 1980 through Dec 31, 2099.
In the future the best way to get information on specific function, properties, methods, classes and other members of the VBA Language you can use the Object Browser.
Marked one is the object browser and when clicked on will open this window (it can also be accessed with pressing F2) In this window enter what you are searching for
One you get results scroll through and look for a more specific item:
Now there are 2 points in the above image:
1) At the bottom of the screen it gives basic detail about this item, in this case
it states that it belongs to the `DateTime` Class, and is a property of that
class, and that it is a Variant.
2) Also in the picture above I have right clicked on the item and selected Help from
the context menu, this will bring up even more details about this item.
As you can see here Microsoft has built in support for this item and gives you details on what it is, what data type it would use and what it returns. Also, how to use and some common notes for when you use it!
VBA.Date and VBA.Time are functions that return the current date and the current time, respectively.
In your editor Tools / References you'll see 'Visual Basic For Applications' is selected. I have absoutely no proof but my idle conjecture is that this is where your VBA.Date (and VBA, everything) lies. Furthermore your F2 investigations show you the truth - It's in the VBA module there. Note you can use VBA.Date or just Date and they are the same thing.
In short it's hard coded in that DLL file referred to in Tools/References.

Support needed with vba programming for a pop up calendar

I have no experience with vba and would much appreciate your assistance with the implementation of a pop-up calendar user form. This link will direct you to the source of the calendar that I am trying to introduce into my workbook:
http://www.ozgrid.com/forum/showthread.php?t=142603
I have copied the class module, the user form, and the module into my workbook. When I launch the macro, this opens up a user form where i can select the date wished on a calendar.
What I miss is to be able to send the date selected in the calendar to a specific cell in my workbook.
I would much appreciate if somebody could guide me through how to write a few lines of code that would send the date selected in the user form to a specific cell in my workbook!
Again, I am very new to this so let me know if anything is unclear in my explanation. I have spent a lot of time on this so any support is highly appreciated! It probably only takes a few moments for you but would mean a lot to me!
Try this post. It semes to give a better guide to work with datepicker control. However it shows coding to make an add-in.
Hence most basic approach for you would be to,
Add a Form
Add datepicker control
code from there
per this article.
But do remember calendar control in Excel/Access can sometimes disappear due this reason mentioned in my post.
If you are planning to use date picker control, here is the code to pass the value from form to anywhere you want ;)
Private Sub myDtPicker_Change()
Dim dtDateSelected as Date
dtDateSelected = myDtPicker.Value
'-- do anything else
End Sub
The class writes the selected Date into a Textbox. After you selected the Date, you can use the value of the textbox to set the value of the Cell.
Private Sub UserForm_Initialize()
Set clsCal = New clsCalendar 'Initialize the Class'
Set clsCal.Form(Me.TextBoxDate) = Me 'Tells the class to write the Selected date'
' into the textbox "Me.TextBoxDate"'
End Sub
So in that example, whenever you select a date, the class will automaticaly store the selected Date in the Textbox.
After you selected the date, you can use the following code to add the value to a cell:
Range("A1").value=TextBoxDate.Value

Hide add-in tabs from MS Office ribbon (esp. PowerPivot tab)

I'm modifying the ribbons of an Excel file, hiding all default and context tabs but only show my own tab. However, once any add-in with its own tab(s) is installed, these tabs are still displayed, as I do not know how to address them.
I know you can remove all tabs using <ribbon startFromScratch="true">, but I need to leave them in place (I actually use a getVisible callback to hide them from the user but show them to Admin).
So, following questions:
Is there any way to apply a "default" getVisible callback for all tabs not known (I guess the answer is no)
How can I figure out tabIDs of other add-in tabs
Given that PowerPivot is more and more widespread (esp. in Excel 2013) - what is the tabID for this tab?
This is an awesome question, there is little documentation or examples about working with third party ribbons. I've done a lot of digging around and can help you with most of what you want. I'll answer you're questions slightly out of order but here goes.
3) The Tab Id for the PowerPivot addin is a qualifier Id (so must be used with idQ) and is tabGemini. You must use it in the name space: Microsoft.AnalysisServices.Modeler.FieldList.
You can check this by adding a namespace to the schema:
xmlns:x1="Microsoft.AnalysisServices.Modeler.FieldList"
and then when declaring your tab's id, use the following to insert your tab before the PowerPivot tab:
insertBeforeQ="x1:tabGemini"
2) I had a hard time finding the tab Id for PowerPivot since it's a VSTO COM addin so you can't access the XML like you can with .xlam files. The answer is simple but you need Office 2010 or later. With Excel open and the addin you are interested open too, go to the File Menu and then Options. Choose Customize Ribbon and on the right of the window at the top choose Customize the Ribbon: Main Tabs. Now uncheck the addins you are interested in and down the bottom hit Import/Export to export the XML schema. Open this file up in a text editor and you can see how they've declared their tab ids.
1) I think the trouble you've got with the getVisible call back is that no matter how you mark up your XML if someone loads up an add-in after you, it'll override whatever you've done. The following is from the Fluent Ribbon for Developers FAQ (http://msdn.microsoft.com/en-us/library/office/aa722523%28v=office.12%29.aspx#a16c7df5-93f3-4920-baa8-7b7290794c15_FAQ)
What happens when two add-ins try to repurpose the same built-in control?
The last add-in that attempts to repurpose the control becomes the active add-in.
Now I haven't gone any further than this, but if you can import/export this board schema into Office then if you can find where this get's imported into, maybe you could manually overwrite it in VBA using the filescripting object. Obviously only if it's stored as text. Bit of a long shot but worth a further look? Good luck!
The PowerPivot tab is a COM Add-In. To view the progID of it and other COM Add-Ins use:
Sub ListCOMAddins()
Dim lngRow As Long, objCOMAddin As COMAddIn
lngRow = 1
With ActiveSheet
For Each objCOMAddin In Application.COMAddIns
.Cells(lngRow, "A").Value = objCOMAddin.Description
.Cells(lngRow, "B").Value = objCOMAddin.Connect
.Cells(lngRow, "C").Value = objCOMAddin.progID
lngRow = lngRow + 1
Next objCOMAddin
End With
End Sub`
In my case the progID of the PowerPivot tab is "Microsoft.AnalysisServices.Modeler.FieldList". So to close the tab use:
Private Sub Workbook_Open()
Application.COMAddIns("Microsoft.AnalysisServices.Modeler.FieldList").Connect = False
End Sub

Resources