0

i'm trying to learn vba and i'm writing at the vba interface some subs that contain the content of what i'm learning. I don't know if this is an efficient method to store the commands and syntaxes that i stood, to study again later, due to this method of studying, when i'm executing/adding some new procedures, sometimes appear some messageboxes on the sheets with some random numbers(WHENEVER I ADD A NEW SUB, when i gave it a command to open another workbook, in the new wb it appears those random numbers...), i still don't know if this is a memory problem of vba or some kind of syntax error that i made by my own. An example of what code i add that was caught into this kind of error is shown below:

Sub atribuirobjeto()

    Dim wb As Workbook
    Dim ws As Worksheet
    Dim box As Range 'variável box - para representar o range e localizar ou definir um intervalo de células

    Set wb = Workbooks(1) 'precisa do set quando for atribuir a objeto
    Set ws = Workbooks(1).Worksheets(1)
    'ou
    Set ws = wb.Worksheets(1) 'pode usar o wb para se refenciar ao objeto workbooks

    'de forma similar, ws engloba o wsheet e o workboooks
    Set box = ws.Range("C40")
    ws.Name = "anotacoes_vba"
    box.Value = 14

    Debug.Print TypeName(box)

End Sub

One of the msgboxes that appears

One of the msgboxes that appears

Full code on this link

  • Do you have any add-ins loaded? What's a sample "message box" that pops up? – BigBen Apr 20 '20 at 19:20
  • By add-ins, you mean stuff like solver, one note and etc? No, i disabled them all. I added some pictures on the post of the msgboxes that happens whenever i made some new subs. The strange fact is that are approximately 6-7 msgboxes, and they were all the same, no matter what new procedure is, are the same msgboxes... – Felipe Carvalho Apr 20 '20 at 20:08
  • Do you have any `Worksheet_Change` event code? – BigBen Apr 20 '20 at 20:10
  • No, i don't think i have any ws_change event code. Is it valid that i post the whole content of this vba code? To get help. Something happens since yesterday, when i add a new workbook by the command workbook.add, inside the new workbook, it appears those same numbers... – Felipe Carvalho Apr 21 '20 at 22:55
  • Sure, go ahead and [edit] your question with more code. – BigBen Apr 21 '20 at 23:55
  • Done! I post it on a link. I made a typo on the past comment, but this error happened when i made the command to open new workbooks too. This error also occurs sometimes when the user adds new subs and etc – Felipe Carvalho Apr 22 '20 at 00:48
  • Can you just get rid of all these `MsgBox`s... for example, `MsgBox (bonuQuan)` seems problematic? Just `Debug.Print` if needed. – BigBen Apr 22 '20 at 00:53
  • If you post just the code that you know about then you probably won't be posting the code that causes the problem since that is likely some event handler you haven't found. In the editor type Ctrl+F to call up the find utility and do a whole project search for MsgBox – John Coleman Apr 22 '20 at 00:53
  • None of the message boxes in the code that you link to look like they could yield a message which looks like the first one (2 numbers with a comma between) – John Coleman Apr 22 '20 at 00:58
  • Also, `MsgBox (calc_c)` is a borderline bug. You are not using the return value of MsgBox, so you should drop the parentheses: `MsgBox calc_c`. In this case it doesn't matter, but if you use `MsgBox(calc_c,vbInformation)` (for example) it would be a syntax error. – John Coleman Apr 22 '20 at 01:03
  • So it's not any of those msgboxes that are making this bug? And as an argument i should not use the () in the majority of the functions? – Felipe Carvalho Apr 23 '20 at 22:53
  • @FelipeCarvalho The msgboxes are a symptom of the bug, not its source, and the msgboxes in the code you linked to are apparently not the msgboxes which are popping up. The bug is probably in code that you haven't shown, and seems to be in code that you have forgotten or don't know about. As far as () go, VBA treates sub calls and function calls differently. Function calls use () but sub calls do not. This is true even when you are calling a function as a sub (in other words, without using its return value). See [this question](https://stackoverflow.com/q/5413765/4996248). – John Coleman Apr 24 '20 at 13:18
  • The whole content of this code was exposed here, i simply copied and pasted it here. You mean some other codes that were on the workbook by default? – Felipe Carvalho Apr 27 '20 at 22:25

0 Answers0