LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default active workbook/sheet

I have a VBA macro (WinXP, Excel 2003) whose job is to split out
individual rows from a worksheet and save the rows as independent
files, using the value in one of the cells to determine the file name.
Because I want to easily retain the layout (mainly the column widths),
the logic I'm using is like this:

1) Grab the header from row 1, plus the content of row 2.
2) Get the filename info out of row 2, columns C and D.
3) Clear all the rows from 3 onward.
4) Save the trimmed-down content as a new file, using the filename
calculated in step 2.
5) Re-open the original, main file.
6) Close the trimmed-down file.
7) Delete row 2 from the main file.

I'm setting this up to be run one line at a time, via a hot-key, so
that if problems arise they can be attended to immediately.

Everything works up through and including step 6. But I cannot get any
editing changes to "take" at step 7. In fact, I cannot even get
message boxes to pop up at that point. I suspect that I am somehow
failing to activate the proper workbook and/or proper worksheet (there
is only one worksheet in the main file).

Here is my code. You can see from commented-out lines that I've been
casting around in the dark, trying to find the lucky combination. I've
tried not activating, activating next, activating previous, activating
by sheet name and workbook name, etc. etc.

Any help would be appreciated. TIA--
--larry

Sub SaveByNameIsbn()
Dim thePath As String
Dim myMainWorkbook As Workbook
Dim myOutputWorkbook As Workbook
Dim theName As String
theName = ActiveWorkbook.FullName
Dim author As Range
Dim isbn As Range

Set author = Range("c2:c2").Item(1)
Set isbn = Range("D2:D2").Item(1)

Dim myRows As Long
myRows = Rows.Count
Rows("3:" & myRows).Clear
'ActiveWorkbook.SaveAs fileName:=thePath & author & "_" & isbn
'set myOutputWorkbook =
Set myOutputWorkbook = ActiveWorkbook
'ActiveWorkbook.SaveAs fileName:=ActiveWorkbook.Path & "\" &
author & "_" & isbn
myOutputWorkbook.SaveAs fileName:=ActiveWorkbook.Path & "\" &
author & "_" & isbn

Set myMainWorkbook = Workbooks.Open(theName, , 0) ' Does zero
force file to be editable?
myOutputWorkbook.Close
'myMainWorkbook.Activate
myMainWorkbook.Sheets("Sheet1").Activate
'ActiveWindow.ActivatePrevious
'ActiveWorkbook.Close
'ActiveWindow.Close
'ActiveWindow.ActivateNext
'myMainWorkbook.Activate
'Dim myMainSheet As Worksheet
'Set myMainSheet = myMainWorkbook.Sheets(1)
'myMainWorkbook.Sheets(1).Activate
'myMainSheet.Activate
'myMainWorkbook.Sheets("Sheet1").Range("a2:a2").Se lect
'myMainWorkbook.Sheets("Sheet1").Rows("2:2").Selec t
MsgBox "debug" ' Please, at least SHOW UP
Rows("2:2").Select
Selection.Delete Shift:=xlUp

GoTo bye

bye:
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy value from active sheet to another workbook sak New Users to Excel 2 June 19th 09 10:52 AM
Copy and Remame Sheet in active Workbook Bjoern[_3_] Excel Programming 7 September 23rd 07 02:49 PM
Save active sheet into new workbook MarkN Excel Programming 3 August 22nd 07 09:00 PM
VB to copy a sheet to active workbook Darin Kramer Excel Programming 4 September 11th 06 09:23 PM
Reliably get sheet 1 of the active workbook Michael D. Ober Excel Programming 6 October 27th 03 07:48 PM


All times are GMT +1. The time now is 10:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"