More vba help please
Per Ardua ad Astraeus
Thread Starter
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
More vba help please
I have been chuntering away happily now for months developing a prog, but need some aid now if poss. Google is coming up short.
I have a workbook "PPrune.xls" which has 3 worksheets, 1, 2 and 3. I wish to be able to select which of the three (or all) I save to a new workbook 'Danny.xls", 1,2 and 3. I'm happy with the selection, and can save the first sheet as sheet 1 - it is adding the next 1 or 2 I am stumped on.
I have a workbook "PPrune.xls" which has 3 worksheets, 1, 2 and 3. I wish to be able to select which of the three (or all) I save to a new workbook 'Danny.xls", 1,2 and 3. I'm happy with the selection, and can save the first sheet as sheet 1 - it is adding the next 1 or 2 I am stumped on.
Join Date: Jan 2012
Location: .
Posts: 2,173
Likes: 0
Received 0 Likes
on
0 Posts
I don't have an answer - I know nowt about spreadsheets, but I suspect the lack if response is that people don't understand the question
What are you actually trying to do - simple resave a spreadsheet under another name? Or are these spreadsheets outputs from a program and you're trying to redirect the outputs to another format? Or what?
What are you actually trying to do - simple resave a spreadsheet under another name? Or are these spreadsheets outputs from a program and you're trying to redirect the outputs to another format? Or what?
Per Ardua ad Astraeus
Thread Starter
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
"What are you actually trying to do - simple resave a spreadsheet under another name? Or are these spreadsheets outputs from a program and you're trying to redirect the outputs to another format? Or what? " - I'm not sure where you got that from, but as you say you don't understand spreadsheets.
I thought "I have a workbook "PPrune.xls" which has 3 worksheets, 1, 2 and 3. I wish to be able to select which of the three (or all) I save to a new workbook 'Danny.xls", 1,2 and 3. I'm happy with the selection, and can save the first sheet as sheet 1 - it is adding the next 1 or 2 I am stumped on."
was pretty straightforward to anyone who understands Excel/Libre-Office programming, and I suspect it is. Hopefully someone will come along one day.
I thought "I have a workbook "PPrune.xls" which has 3 worksheets, 1, 2 and 3. I wish to be able to select which of the three (or all) I save to a new workbook 'Danny.xls", 1,2 and 3. I'm happy with the selection, and can save the first sheet as sheet 1 - it is adding the next 1 or 2 I am stumped on."
was pretty straightforward to anyone who understands Excel/Libre-Office programming, and I suspect it is. Hopefully someone will come along one day.
Join Date: Jan 2012
Location: .
Posts: 2,173
Likes: 0
Received 0 Likes
on
0 Posts
the comment "I have been chuntering away happily now for months developing a prog" is likely to throw a few people in a false direction then
The assumption would be that the spreadsheets are outputs from some other program that you're working on...
The assumption would be that the spreadsheets are outputs from some other program that you're working on...
Per Ardua ad Astraeus
Thread Starter
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
The assumption would be that the spreadsheets are outputs from THIS program that you're working on.
Per Ardua ad Astraeus
Thread Starter
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
No sp, that's a good suggestion, but I am well past that stage. I need someone with a good knowledge of VBA who is prepared to help here (by PM/email).
Since you ask, the routine works fine as a keyboard recorded macro but will not run correctly in the main programme.
Since you ask, the routine works fine as a keyboard recorded macro but will not run correctly in the main programme.
Join Date: Jan 2012
Location: .
Posts: 2,173
Likes: 0
Received 0 Likes
on
0 Posts
Per Ardua ad Astraeus
Thread Starter
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
Yes, Milo, it is on the list. I am already 'registered from some years back, but I am a bit busy and I had hoped for a quick fix here.
Last edited by BOAC; 15th Jun 2012 at 18:05.
BOAC,
Google search bought up this
MSlink
That should give you some ideas
Max
Google search bought up this
MSlink
Sub Mover3()
Dim BkName As String
Dim NumSht As Integer
Dim BegSht As Integer
'Starts with second sheet - replace with index number of starting sheet.
BegSht = 2
'Moves two sheets - replace with number of sheets to move.
NumSht = 2
BkName = ActiveWorkbook.Name
For x = 1 To NumSht
'Moves second sheet in source to front of designated workbook.
Workbooks(BkName).Sheets(BegSht).Move _
Before : = Workbooks("Test.xls").Sheets(1)
'In each loop, the next sheet in line becomes indexed as number 2.
'Replace Test.xls with the full name of the target workbook you want.
Next
End Sub
Dim BkName As String
Dim NumSht As Integer
Dim BegSht As Integer
'Starts with second sheet - replace with index number of starting sheet.
BegSht = 2
'Moves two sheets - replace with number of sheets to move.
NumSht = 2
BkName = ActiveWorkbook.Name
For x = 1 To NumSht
'Moves second sheet in source to front of designated workbook.
Workbooks(BkName).Sheets(BegSht).Move _
Before : = Workbooks("Test.xls").Sheets(1)
'In each loop, the next sheet in line becomes indexed as number 2.
'Replace Test.xls with the full name of the target workbook you want.
Next
End Sub
Max
Per Ardua ad Astraeus
Thread Starter
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
Good find, thanks Agent. I'll give that a go. Since the intitial responses I have been looking at a different approach, so with thanks to all for the help I will let this thread die..