Include the value of a variable within another string

Asked

Viewed 100 times

2

I wonder if it is possible to place the value of a variable type string inside another string.

Example:

Dim name As String
Set name  = "Bruno"

ActiveWorkbook.SaveAs Filename:= _"\Colegio\compartilhamentos\secretaria\aluno - name.xlsx

That way the name of the file would look like this: College student secretary shares - Bruno.xlsx

  • 1

    Perhaps the instruction Set make a mistake, Osvaldo. Set is the instruction to assign OBJECTS to a variable. To assign values that are not objects, the correct instruction is to Let (which no one uses because it is the default implicit instruction). Therefore, your second line should be only name = "Bruno"

  • Thank you, Caesar! I was unaware of this information.

1 answer

3


Use the concatenator &. Do the following:

Dim name As String
Set name  = "Bruno"

ActiveWorkbook.SaveAs Filename:= _"\Colegio\compartilhamentos\secretaria\aluno - " & name & ".xlsx"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.