ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA syntax (https://www.excelbanter.com/excel-discussion-misc-queries/224150-vba-syntax.html)

dhstein

VBA syntax
 
I have some code in a macro that was recorded like this:
TableDestination:="[MyWorkbook.xlsm]Sales!R5C1"

I would like to replace Myworkbook.xlsm with "ActiveWorkbook

Is this the syntax:

TableDestination:="[ActiveWorkbook]Reorder!R5C1" ?

OR

TableDestination:="ActiveWorkbook.Reorder!R5C1"

OR something else?

Thanks for any help on this

Sheeloo[_3_]

VBA syntax
 
ActiveWorkbook.Sheets("Sales").Cells(5, 1)

it has to be of the form
workbook.worksheet.range

"dhstein" wrote:

I have some code in a macro that was recorded like this:
TableDestination:="[MyWorkbook.xlsm]Sales!R5C1"

I would like to replace Myworkbook.xlsm with "ActiveWorkbook

Is this the syntax:

TableDestination:="[ActiveWorkbook]Reorder!R5C1" ?

OR

TableDestination:="ActiveWorkbook.Reorder!R5C1"

OR something else?

Thanks for any help on this


Jarek Kujawa[_2_]

VBA syntax
 
try:

Dim k as String
k = "'[" & ThisWorkbook.Name & "]Reorder'!R5C1"
TableDestination:= k


On 13 Mar, 01:46, dhstein wrote:
I have some code in a macro that was recorded like this: *
TableDestination:="[MyWorkbook.xlsm]Sales!R5C1"

I would like to replace Myworkbook.xlsm with "ActiveWorkbook

Is this the syntax:

TableDestination:="[ActiveWorkbook]Reorder!R5C1" * ?

OR

TableDestination:="ActiveWorkbook.Reorder!R5C1"

OR something else?

Thanks for any help on this



Dave Peterson

VBA syntax
 
I like to let excel's vba take care of the syntax.

dim DestCell as range
set destcell = workbooks("myworkbook.xlsm").worksheets("sales").c ells(5,1)
or this--it doesn't matter if you use .cells() or .range()
set destcell = workbooks("myworkbook.xlsm").worksheets("sales").r ange("a5")
or
set destcell = activeworkbook.worksheets("sales").range("a5")
or (if you're running from the correct worksheet)
set destcell = activesheet.range("a5")

....tabledestination:=destcell.address(external:=t rue), ...




dhstein wrote:

I have some code in a macro that was recorded like this:
TableDestination:="[MyWorkbook.xlsm]Sales!R5C1"

I would like to replace Myworkbook.xlsm with "ActiveWorkbook

Is this the syntax:

TableDestination:="[ActiveWorkbook]Reorder!R5C1" ?

OR

TableDestination:="ActiveWorkbook.Reorder!R5C1"

OR something else?

Thanks for any help on this


--

Dave Peterson


All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com