Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Trouble making another worksheet active

I have a workbook with 10 worksheets, and I want a button on the last one to
create text files of the date in each of the other 9. I made a command
button on the last page ("Summary") and I want the button to perform this
operation on the first page ("Header"). Here's the code:

Private Sub BtnExport_Click()
' This saves the data from the Header worksheet as a .txt file called
"Header.txt"

' Declare variables
Dim Col As Integer
Dim outputline As String
Dim fs As Object
Dim a As Object

' Create a new text file
Set fs = CreateObject("scripting.filesystemobject")
Set a = fs.createtextfile("c:\header.txt", True)

' Set the Header worksheet as the active worksheet
Worksheets("Header").Activate

For Col = 1 To 9
If Len(outputline) 0 Then
outputline = outputline & ";" & Cells(3, Col)
Else
outputline = Cells(3, Col)
End If
Next Col

a.writeline (outputline)

End Sub

The function works great, but it outputs the data from the "Summary"
worksheet instead of the "Header" worksheet. What am I doing wrong?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Trouble making another worksheet active

Hi Todd:

I got your macro to work by putting it in a standard module, making it
public, and having the button call it
--
Gary''s Student - gsnu200748


"Todd K." wrote:

I have a workbook with 10 worksheets, and I want a button on the last one to
create text files of the date in each of the other 9. I made a command
button on the last page ("Summary") and I want the button to perform this
operation on the first page ("Header"). Here's the code:

Private Sub BtnExport_Click()
' This saves the data from the Header worksheet as a .txt file called
"Header.txt"

' Declare variables
Dim Col As Integer
Dim outputline As String
Dim fs As Object
Dim a As Object

' Create a new text file
Set fs = CreateObject("scripting.filesystemobject")
Set a = fs.createtextfile("c:\header.txt", True)

' Set the Header worksheet as the active worksheet
Worksheets("Header").Activate

For Col = 1 To 9
If Len(outputline) 0 Then
outputline = outputline & ";" & Cells(3, Col)
Else
outputline = Cells(3, Col)
End If
Next Col

a.writeline (outputline)

End Sub

The function works great, but it outputs the data from the "Summary"
worksheet instead of the "Header" worksheet. What am I doing wrong?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Trouble making another worksheet active

Well this falls under the "why didn't I think of that" category. Great idea
and quick response, thanks!

"Gary''s Student" wrote:

Hi Todd:

I got your macro to work by putting it in a standard module, making it
public, and having the button call it
--
Gary''s Student - gsnu200748


"Todd K." wrote:

I have a workbook with 10 worksheets, and I want a button on the last one to
create text files of the date in each of the other 9. I made a command
button on the last page ("Summary") and I want the button to perform this
operation on the first page ("Header"). Here's the code:

Private Sub BtnExport_Click()
' This saves the data from the Header worksheet as a .txt file called
"Header.txt"

' Declare variables
Dim Col As Integer
Dim outputline As String
Dim fs As Object
Dim a As Object

' Create a new text file
Set fs = CreateObject("scripting.filesystemobject")
Set a = fs.createtextfile("c:\header.txt", True)

' Set the Header worksheet as the active worksheet
Worksheets("Header").Activate

For Col = 1 To 9
If Len(outputline) 0 Then
outputline = outputline & ";" & Cells(3, Col)
Else
outputline = Cells(3, Col)
End If
Next Col

a.writeline (outputline)

End Sub

The function works great, but it outputs the data from the "Summary"
worksheet instead of the "Header" worksheet. What am I doing wrong?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Trouble making another worksheet active

You are very welcome.
--
Gary''s Student - gsnu200748


"Todd K." wrote:

Well this falls under the "why didn't I think of that" category. Great idea
and quick response, thanks!

"Gary''s Student" wrote:

Hi Todd:

I got your macro to work by putting it in a standard module, making it
public, and having the button call it
--
Gary''s Student - gsnu200748


"Todd K." wrote:

I have a workbook with 10 worksheets, and I want a button on the last one to
create text files of the date in each of the other 9. I made a command
button on the last page ("Summary") and I want the button to perform this
operation on the first page ("Header"). Here's the code:

Private Sub BtnExport_Click()
' This saves the data from the Header worksheet as a .txt file called
"Header.txt"

' Declare variables
Dim Col As Integer
Dim outputline As String
Dim fs As Object
Dim a As Object

' Create a new text file
Set fs = CreateObject("scripting.filesystemobject")
Set a = fs.createtextfile("c:\header.txt", True)

' Set the Header worksheet as the active worksheet
Worksheets("Header").Activate

For Col = 1 To 9
If Len(outputline) 0 Then
outputline = outputline & ";" & Cells(3, Col)
Else
outputline = Cells(3, Col)
End If
Next Col

a.writeline (outputline)

End Sub

The function works great, but it outputs the data from the "Summary"
worksheet instead of the "Header" worksheet. What am I doing wrong?

Reply
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
Trouble with 'save as' or making changes vegasboy702 Excel Discussion (Misc queries) 0 November 29th 06 10:10 PM
Trouble with 'save as' or making changes vegasboy702 Excel Discussion (Misc queries) 0 November 29th 06 10:00 PM
Trouble returning to original active cell Giznawz Excel Programming 3 October 3rd 05 01:52 PM
Trouble with making a 3D reference absolute Sherry Excel Discussion (Misc queries) 1 March 24th 05 09:28 PM
Trouble making a report of all Files within a Folder and all Subfolders? SuperJas Excel Programming 2 April 2nd 04 02:41 AM


All times are GMT +1. The time now is 10:46 AM.

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

About Us

"It's about Microsoft Excel"