Textbox not support for property and menthod in VBA ppt - vba

Here is my code
Sub Loadde()
If Slide3.Shapes("MA_VONG") = 1 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide6.Shapes("1").TextFrame.TextRange
Slide5.Shapes("Q2").TextFrame.TextRange = Slide6.Shapes("2").TextFrame.TextRange
Slide5.Shapes("Q3").TextFrame.TextRange = Slide6.Shapes("3").TextFrame.TextRange
Slide5.Shapes("Q4").TextFrame.TextRange = Slide6.Shapes("4").TextFrame.TextRange
Slide5.Shapes("Q5").TextFrame.TextRange = Slide6.Shapes("5").TextFrame.TextRange
ElseIf Slide3.Shapes("MA_VONG") = 2 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide7.Shapes("1").TextFrame.TextRange
Slide5.Shapes("Q2").TextFrame.TextRange = Slide7.Shapes("2").TextFrame.TextRange
Slide5.Shapes("Q3").TextFrame.TextRange = Slide7.Shapes("3").TextFrame.TextRange
Slide5.Shapes("Q4").TextFrame.TextRange = Slide7.Shapes("4").TextFrame.TextRange
Slide5.Shapes("Q5").TextFrame.TextRange = Slide7.Shapes("5").TextFrame.TextRange
End If
End Sub
At first, it work fine but after that, it showed an error that the Qs (in Slide 5) were not supported
I tried to make it more simple and it still does not work.
Sub Loadde()
If Slide3.Shapes("MA_VONG") = 1 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide6.Shapes("1").TextFrame.TextRange
Slide5.Shapes("Q2").TextFrame.TextRange = Slide6.Shapes("2").TextFrame.TextRange
Slide5.Shapes("Q3").TextFrame.TextRange = Slide6.Shapes("3").TextFrame.TextRange
Slide5.Shapes("Q4").TextFrame.TextRange = Slide6.Shapes("4").TextFrame.TextRange
Slide5.Shapes("Q5").TextFrame.TextRange = Slide6.Shapes("5").TextFrame.TextRange
End If
End Sub
Can somebody explain to me what is wrong with this code?

A few suggestions:
First, it's not clear whether you've DIMmed your variables elsewhere.
Next, Slide3.Shapes("some name") = 1 will fail. There's no such property. What exactly are you trying to test for here? The text in the shape or that the shape exists at all? Or something else?
Finally, just to be sure, IS there actually a shape named 1 on Slide6 or are you trying to reference the first shape on the slide, in which case you'd use Slide6.Shapes(1) (not "1" in quotes).
Sub Loadde()
If Slide3.Shapes("MA_VONG") = 1 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide6.Shapes("1").TextFrame.TextRange
' ...
ElseIf Slide3.Shapes("MA_VONG") = 2 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide7.Shapes("1").TextFrame.TextRange
' ...
End If
End Sub

Related

Word VBA- On error go to msgbox rather than crashing userform

How would I incorporate "on error" into my code so that if a user enters something into a textbox that is not a date formatted to MM/DD/YYYY or left blank it will not exit out of my userform. Other solutions are appreciated as well!
The code:
Private Sub CommandButton1_Click()
Dim s As String
s = Me.TextBoxx25.Text
If s = "" Then
ElseIf DateDiff("d", Me.TextBoxx25.Text, "11/12/2020") > 0 Then
Doc1.Bookmarks("bmrow1").Range.Cells.Delete
Doc2.Variables("TextBoxx25").Value = Me.TextBoxx25.Text
Doc2.Variables("TextBoxx1").Value = Me.TextBoxx1.Text
Doc2.Variables("TextBoxx7").Value = Me.TextBoxx7.Text
Doc2.Variables("TextBoxx13").Value = Me.TextBoxx13.Text
Doc2.Variables("TextBoxx19").Value = Me.TextBoxx19.Text
Doc2.Variables("TextBoxx31").Value = Me.TextBoxx31.Text
Else
Doc1.Variables("TextBoxx25").Value = Me.TextBoxx25.Text
Doc1.Variables("TextBoxx1").Value = Me.TextBoxx1.Text
Doc1.Variables("TextBoxx7").Value = Me.TextBoxx7.Text
Doc1.Variables("TextBoxx13").Value = Me.TextBoxx13.Text
Doc1.Variables("TextBoxx19").Value = Me.TextBoxx19.Text
Doc1.Variables("TextBoxx31").Value = Me.TextBoxx31.Text
Doc2.Bookmarks("bmrow1").Range.Cells.Delete
End If
It would have to display a msgbox that says please format as (MM/DD/YYYY)

How to run macro when cell value changed by formula results for code that hides/unhides rows based on formula result?

I have a worksheet that hides or unhides rows based on the value as a cell. I end up getting a run time error that reads:
-2147417848 (80010108):
Method 'Hidden' of object 'Range' failed, with a yellow arrow pointing at the first Rows equation
and then another run-time error '1004':
Unable to set the hidden property of the range class.
Option Explicit
Private Sub Worksheet_Calculate()
Rows("1:26").EntireRow.Hidden = [a1] = 0
Rows("27:52").EntireRow.Hidden = [a27] = 0
Rows("53:78").EntireRow.Hidden = [a53] = 0
Rows("79:104").EntireRow.Hidden = [a79] = 0
Rows("105:130").EntireRow.Hidden = [a105] = 0
Rows("131:156").EntireRow.Hidden = [a131] = 0
Rows("157:182").EntireRow.Hidden = [a157] = 0
Rows("183:208").EntireRow.Hidden = [a183] = 0
Rows("209:234").EntireRow.Hidden = [a209] = 0
End Sub
Should look like this:
Private Sub Worksheet_Calculate()
Dim v
v = Me.Range("A1").Value
Me.Range("1:26").EntireRow.Hidden = (v = 0)
End Sub
I don't know if you need to handle potential error values in the A1 formula result.
EDIT: try this - it looks like your worksheet is entering a loop where the hide/show is re-triggering another calculation, etc, etc
Private Sub Worksheet_Calculate()
On Error GoTo haveError
Application.EnableEvents = False
Me.Range("1:26").EntireRow.Hidden = [a1] = 0
Me.Range("27:52").EntireRow.Hidden = [a27] = 0
Me.Range("53:78").EntireRow.Hidden = [a53] = 0
Me.Range("79:104").EntireRow.Hidden = [a79] = 0
Me.Range("105:130").EntireRow.Hidden = [a105] = 0
Me.Range("131:156").EntireRow.Hidden = [a131] = 0
Me.Range("157:182").EntireRow.Hidden = [a157] = 0
Me.Range("183:208").EntireRow.Hidden = [a183] = 0
Me.Range("209:234").EntireRow.Hidden = [a209] = 0
haveError:
Application.EnableEvents = True
End Sub

VBA: Prevent _Click Event from Triggering at Value Change

I have been had this issue in mind for months and it remains unresolved after so much research. I'm working with Excel Checkboxes and trying to make the system foolproof whereas "if A & B cannot occur together, if A is clicked and you click B, then the macro unclicks A for you".
However, the issue I'm running into is that this starts (as shown in my code below) an infinite loop,
The first Sub:
Private Sub CheckBoxD11_Click()
If CheckBoxD12.Value = True Then
CheckBoxD12.Value = False
Worksheets("Dynamic_Parking_Sheet").Range("D9").Interior.ColorIndex = 20
CheckBoxD11.Value = True
Worksheets("Dynamic_Parking_Sheet").Range("B8:E8").Interior.ColorIndex = 2
End If
TextBox1_Change
TextBox2_Change
If CheckBoxD11.Value = True Then
Worksheets("Dynamic_Parking_Sheet").Range("B9:E9").Interior.Color = RGB(221, 221, 221)
Worksheets("Dynamic_Parking_Sheet").Range("D8").Interior.ColorIndex = 4
Else
Worksheets("Dynamic_Parking_Sheet").Range("B9:E9").Interior.ColorIndex = 20
Worksheets("Dynamic_Parking_Sheet").Range("D8").Interior.ColorIndex = 2
End If
End Sub
.. and the second Sub:
Private Sub CheckBoxD12_Click()
If CheckBoxD11.Value = True Then
CheckBoxD11.Value = False
Worksheets("Dynamic_Parking_Sheet").Range("D8").Interior.ColorIndex = 2
CheckBoxD12.Value = True
Worksheets("Dynamic_Parking_Sheet").Range("B9:E9").Interior.ColorIndex = 20
End If
TextBox1_Change
TextBox2_Change
If CheckBoxD12.Value = True Then
Worksheets("Dynamic_Parking_Sheet").Range("B8:E8").Interior.Color = RGB(221, 221, 221)
Worksheets("Dynamic_Parking_Sheet").Range("D9").Interior.ColorIndex = 4
Else
Worksheets("Dynamic_Parking_Sheet").Range("B8:E8").Interior.ColorIndex = 2
Worksheets("Dynamic_Parking_Sheet").Range("D9").Interior.ColorIndex = 20
End If
End Sub
I tried working a bit with public flags, but the issue persisted.
Any advice?
Thank you,
~Deut
When you want checkboxes to uncheck each other, try simplifying your code to something like this:
CheckBoxD12.Value = Not CheckBoxD11.value
It would work quite well and there should be no loops.
Or something like this, made simple:
Private Sub chb_A_Click()
If chb_A Then chb_B = False
End Sub
Private Sub chb_B_Click()
If chb_B Then chb_A = False
End Sub
The idea here is that it only checks for being checked to allow the option for both checkboxes to be unchecked.

What else can cause an AxWindowsMediaPlayer to play?

I have a button in my program that grabs a bunch of information from a DataGridView object (volume, url, delay, etc) and using that, it plays a file. I'm trying to get the delay to work (wait x number of seconds before playing) and I'm pretty it will work, but whenever I press the button, the play starts immediately. There is no Ctlcontrols.play() anywhere in the program except after the delay, so I have no idea what is causing it to play.
I explained my problem a little bit more in comments. Sorry if I didn't explain my code very well. If you could just tell my what else could be causing my player to start immediately, that would probably be enough.
'snd_btn_go is the button that is supposed to start it.
'This sub doesn't matter as much for the problem, it will just go to SndCueGO() if both numbers are in the valid range.
Private Sub snd_btn_go_Click(sender As Object, e As EventArgs) Handles snd_btn_go.Click
Dim cue1 As Integer
Dim cue2 As Integer
cue1 = If(Integer.TryParse(snd_txt_cue_1.Text, cue1), Int(snd_txt_cue_1.Text), snd_num1)
If snd_txt_cue_2.Text <> "" Then
cue2 = If(Integer.TryParse(snd_txt_cue_2.Text, cue2), Int(snd_txt_cue_2.Text), snd_num2)
Else
cue2 = -1
End If
If (cue1 <= dgSound.Rows.Count - 1 And cue1 > 0) Then
SndCueGO(cue1, cue2)
End If
End Sub
'This sub pulls all the info from the correct row in the DataGrid and assigns it to a list. It'll check if the start volume and end volume are the same and if they're not, it'll fade to the end volume.
Private Sub SndCueGO(cue1, cue2)
Dim cues() = {cue1, cue2}
snd_num1 = cue1
Dim cuedata1 = snd_ds.Tables(0).Rows(cue1 - 1)
Dim cuedata2 = snd_ds.Tables(0).Rows(cue1 - 1)
If cue2 <> -1 Then
snd_num2 = cue2
cuedata2 = snd_ds.Tables(0).Rows(cue2 - 1)
End If
Dim data() = {cuedata1, cuedata2}
For i = 0 To 1
If cues(i) <> -1 Then
snd_delay(i) = data(i).Item("Delay")
snd_startvol(i) = safeNum(data(i).Item("Start_Vol."))
snd_file(i) = data(i).Item("File")
snd_in(i) = data(i).Item("Fade_In")
snd_out(i) = data(i).Item("Fade_Out")
snd_vol(i) = safeNum(data(i).Item("Vol."))
snd_hold(i) = data(i).Item("Hold")
snd_af(i) = If(data(i).Item("AF") = "", False, True)
player_list(i).URL = snd_file(i)
snd_current(i) = snd_startvol(i)
If snd_startvol(i) <> snd_vol(i) Then 'snd_startvol(i) and snd_vol(i) were the same in all my tests, so this should not run.
snd_next(i) = snd_vol(i)
Dim num_steps_up = snd_in(i) * snd_speed
Dim num_steps_down = snd_out(i) * snd_speed
Dim diff = snd_vol(i) - snd_startvol(i)
Dim small_step As Single
If diff > 0 Then
small_step = diff / num_steps_up
ElseIf diff < 0 Then
small_step = diff / num_steps_down
End If
snd_steps(i) = small_step
timer_snd_fade.Tag = 0
timer_snd_fade.Enabled = True
End If
timer_snd_master.Tag = 0 'resets the tag to 0
timer_snd_master.Enabled = True 'Starts timer
End If
Next
End Sub
Private Sub timer_snd_master_Tick(sender As Object, e As EventArgs) Handles timer_snd_master.Tick
If sender.Tag = snd_delay(0) Then
Player1.Ctlcontrols.play() 'This is the only play command in the program
Debug.Print("tag " & sender.Tag) 'These print after the delay
Debug.Print("delay " & snd_delay(0))
End If
sender.Tag += 1
End Sub
Inspect the:
AxWindowsMediaPlayer player1 = ...; // get the player from UI
IWMPSettings sett = player.settings;
sett.autoStart == ??
see the docs.
Probably it is set to true, as it's default value. Simply set it to false it the player will not play until Ctlcontrols.play() is invoked.

access - reset all comboboxes to itemdata(1) in form

I have about 8 combo-boxes on a form. When a user clicks the button "reset" I would like all the combo boxes to display the first itemdata in the combo box. The code below returns null and doesn't work:
Private Sub Command1_Click()
Me.Combo1.ItemData (1)
Me.Combo2.ItemData (1)
Me.Combo3.ItemData (1)
Me.Combo4.ItemData (1)
Me.Combo5.ItemData (1)
Me.Combo6.ItemData (1)
Me.Combo7.ItemData (1)
Me.Combo8.ItemData (1)
End Sub
If it's MS Access your working with, you'll need to do something like this:
Private Sub Command1_Click()
Me.Combo1.Value = Nothing
Me.Combo2.Value = Nothing
Me.Combo3.Value = Nothing
Me.Combo4.Value = Nothing
Me.Combo5.Value = Nothing
Me.Combo6.Value = Nothing
Me.Combo7.Value = Nothing
Me.Combo8.Value = Nothing
End Sub
Assuming you want to set all the ComboBoxes back to a blank value.
Try this:
Private Sub Command1_Click()
Me.Combo1.SelectedIndex = 0
Me.Combo2.SelectedIndex = 0
Me.Combo3.SelectedIndex = 0
Me.Combo4.SelectedIndex = 0
Me.Combo5.SelectedIndex = 0
Me.Combo6.SelectedIndex = 0
Me.Combo7.SelectedIndex = 0
Me.Combo8.SelectedIndex = 0
End Sub
Something like Me.Combo1.SelectedIndex = 0
Usually...