Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to work on a new worksheet

Im trying to work on a new worksheet using workbooks.add, but when i
try to put some data on this new workbook, the data fills the original
workbook, where my macro is.

this is my macro:

cenario = Sheet1.Range("cdimportacao")

Workbooks.Add

Dim hoje As Date
Dim sfilename As String

sfilename = Format(Now(), "ddmmyyyy")
hoje = Format(Now(), "dd/mm/yyyy")
data = "DATA"

Sheet1.Cells(1, 1).Value = data
Sheet1.Cells(1, 2).Value = hoje
Sheet1.Range("A1:E2545").Value = cenario

ActiveWorkbook.SaveAs Filename:="c:\place\" & sfilename, _
FileFormat:=xlText, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Can someone help me with this? Appears to be basic.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default How to work on a new worksheet

Hi vkfuri-

I think you just need to make the workbook you add the "Active" workbook.

Workbooks(Workbooks.Count).Activate

You may also need to change Sheet1 to ActiveSheet.

John

"vkfuri" wrote:

Im trying to work on a new worksheet using workbooks.add, but when i
try to put some data on this new workbook, the data fills the original
workbook, where my macro is.

this is my macro:

cenario = Sheet1.Range("cdimportacao")

Workbooks.Add

Dim hoje As Date
Dim sfilename As String

sfilename = Format(Now(), "ddmmyyyy")
hoje = Format(Now(), "dd/mm/yyyy")
data = "DATA"

Sheet1.Cells(1, 1).Value = data
Sheet1.Cells(1, 2).Value = hoje
Sheet1.Range("A1:E2545").Value = cenario

ActiveWorkbook.SaveAs Filename:="c:\place\" & sfilename, _
FileFormat:=xlText, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Can someone help me with this? Appears to be basic.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to work on a new worksheet

Thats it, works great now.. thanks a lot.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to work on a new worksheet

i didn't complete your entire macro, but you should always qualify your ranges,
especially if you use multiple workbooks.

Sub test()
Dim NewBook As Workbook
Dim sfilename As String
Dim hoje As Date
Dim sdata As String
Dim wb2 As Workbook
Set wb2 = Workbooks.Add

sfilename = Format(Now(), "ddmmyyyy")
hoje = Format(Now(), "dd/mm/yyyy")
sdata = "DATA"

wb2.Worksheets("Sheet1").Cells(1, 1).Value = sdata
wb2.Worksheets("Sheet1").Cells(1, 2).Value = hoje


End Sub

--


Gary

"vkfuri" wrote in message
...
Im trying to work on a new worksheet using workbooks.add, but when i
try to put some data on this new workbook, the data fills the original
workbook, where my macro is.

this is my macro:

cenario = Sheet1.Range("cdimportacao")

Workbooks.Add

Dim hoje As Date
Dim sfilename As String

sfilename = Format(Now(), "ddmmyyyy")
hoje = Format(Now(), "dd/mm/yyyy")
data = "DATA"

Sheet1.Cells(1, 1).Value = data
Sheet1.Cells(1, 2).Value = hoje
Sheet1.Range("A1:E2545").Value = cenario

ActiveWorkbook.SaveAs Filename:="c:\place\" & sfilename, _
FileFormat:=xlText, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Can someone help me with this? Appears to be basic.



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
Link one worksheet in a workbook to another worksheet in same work bjswise Excel Discussion (Misc queries) 1 February 6th 10 12:09 AM
Retrieving data into worksheet from another worksheet in same work Tasha Excel Discussion (Misc queries) 2 August 6th 09 03:51 PM
How does a module of VB work in a Worksheet? VJ Sharma[_2_] Excel Worksheet Functions 1 April 30th 09 04:15 PM
Copying the active worksheet to another worksheet in the same work queenmaam Excel Worksheet Functions 5 March 25th 08 06:56 PM
I need a work around for a protected worksheet Richard Setting up and Configuration of Excel 1 December 22nd 07 10:28 PM


All times are GMT +1. The time now is 02:40 AM.

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"