Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Changing a csv file opened as hidden workbook

Hi all

Have piece of code that opens a csv workbook in hidden mode and then list data out.

The csv format has changed and I want to insert a row and delete a column... can this bee done with hidden workbooks/ sheets??

cheers

George
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Changing a csv file opened as hidden workbook

Ggalla1779 formulated the question :
Hi all

Have piece of code that opens a csv workbook in hidden mode and then list
data out.

The csv format has changed and I want to insert a row and delete a column...
can this bee done with hidden workbooks/ sheets??

cheers

George


Yes! Just use a fully qualified ref to the sheet in the hidden
workbook. Of course, you'll need to know where to insert the row and
which column to delete.

Example...

Sub EditHiddenWkb()
Dim wks As Worksheet
Set wks = Workbooks("Book1").Sheets(1)
With wks
.Rows(2).Insert shift:=xlDown: .Columns(2).Delete
End With
End Sub

...where Workbooks("Book1") is hidden and Sheets(1) contains data. A new
row is inserted AT row 2, moving row 2's data into row 3 position and
so on down the sheet. Columns("B") is deleted, moving column "C" into
column B's position and so on across the sheet.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Changing a csv file opened as hidden workbook

On Monday, 25 June 2012 02:48:18 UTC+1, GS wrote:
Ggalla1779 formulated the question :
Hi all

Have piece of code that opens a csv workbook in hidden mode and then list
data out.

The csv format has changed and I want to insert a row and delete a column...
can this bee done with hidden workbooks/ sheets??

cheers

George


Yes! Just use a fully qualified ref to the sheet in the hidden
workbook. Of course, you'll need to know where to insert the row and
which column to delete.

Example...

Sub EditHiddenWkb()
Dim wks As Worksheet
Set wks = Workbooks("Book1").Sheets(1)
With wks
.Rows(2).Insert shift:=xlDown: .Columns(2).Delete
End With
End Sub

..where Workbooks("Book1") is hidden and Sheets(1) contains data. A new
row is inserted AT row 2, moving row 2's data into row 3 position and
so on down the sheet. Columns("B") is deleted, moving column "C" into
column B's position and so on across the sheet.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Thanks Gary

Is there a way to make it visible or save changes....so I can check if I have changed the csv file correctly?

cheers George
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Changing a csv file opened as hidden workbook

Ggalla1779 wrote on 6/25/2012 :
Sub EditHiddenWkb()
Dim wks As Worksheet, wkb As Workbook
Dim vAns As Variant, sMsg As String

Set wkb = Workbooks("my.csv"): Set wks = wkb.Sheets(1)
With wkb
'Get the position to insert a new row,
'and the label of the column to delete.
sMsg = "Enter the row number position to insert the new row AND " _
& "the label of the column to delete, separated by a comma." _
& vbCrLf & vbCrLf & "Example: 2,B "
vAns = InputBox(sMsg)
If vAns = False Then Exit Sub '//user cancels

'Insert row and delete column
vAns = Split(vAns, ",")
With wks
.Rows(vAns(0)).Insert shift:=xlDown: .Columns(vAns(1)).Delete
End With 'wks

'Confirm success
.Visible = True
sMsg = "Do you want to save the changes to " & wkb.Name & " ?"
vAns = MsgBox(sMsg, vbYesNo)
.Visible = False: If vAns = vbYes Then .Save Else .Saved = True
End With 'wkb
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Changing a csv file opened as hidden workbook


I tried that bu didnt work, changed it a bit

Set xlAppx = New Excel.Application
Set wkb = xlAppx.Workbooks.Open(Filename:=MyFile)
Set wks = wkb.Sheets(1)

wkb.Visible = True

Doesnt like this says its .Visible isnt available..this will be excel 2003


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Changing a csv file opened as hidden workbook

Ggalla1779 explained on 6/26/2012 :
I tried that bu didnt work, changed it a bit

Set xlAppx = New Excel.Application


Why are you starting a new instance of Excel? I thought the hidden
workbook was in the running instance!

Set wkb = xlAppx.Workbooks.Open(Filename:=MyFile)
Set wks = wkb.Sheets(1)

wkb.Visible = True

Doesnt like this says its .Visible isnt available..this will be excel 2003


Well, I tested the code in XL2003 and it worked for me. The code
assumes the hidden workbook is in the same instance of Excel that the
code is running in.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Changing a csv file opened as hidden workbook



Am modifying code thats there they open new instance for hidden workbook so user doesnt see it
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Changing a csv file opened as hidden workbook

Ggalla1779 formulated the question :

Am modifying code thats there they open new instance for hidden workbook so
user doesnt see it


That's not necessary because you can open it in the same instance and
hide the workbook there. In either case, the code I posted worked for
me using the same instance. The approach you're using is a bit more
complex but should still work as long as you have a fully qualified ref
to the instance and the workbook/worksheet you're working on.

Alternatively, you could use standard VB[A] procedures for file I/O to
read the CSV into memory and work on it there (or 'dump' it into a
hidden temp worksheet). When you want to view the data just 'unhide'
the temp worksheet. When satisfied the data is correct just 'dump' it
back into a CSV and delete the temp worksheet. This will be orders of
magnitude faster and no memory spaces to cleanup. (Every object you
create must have space reserved for it in memory. This needs to be
released as you're done with each object)

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Changing a csv file opened as hidden workbook

Hi Garry thanks for reply

The reason they used a new workbook is the main spreadsheet is protected and unlocked as they need it

Opening a new workbook was the workaround for it....they do it alot tbh and I think its really wasteful...

I got it working by making ref to sheet opened and then copying the hidden sheet, then setting the ref to that. I felt a pang as I copied sheet !!

so now its kinda getting there but had to put in the sheet ref here and there so there rest of code would work
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
Workbook has [Group] at the end of teh file name when opened belinda Excel Programming 1 November 21st 08 01:12 PM
Workbook has [Group] at the end of teh file name when opened MikeR-Oz New Users to Excel 2 September 12th 08 12:55 PM
Keeping a workbook hidden when opened via VBA??? Simon Lloyd[_585_] Excel Programming 3 October 6th 04 03:21 PM
Keeping a workbook hidden when opened via VBA??? Simon Lloyd[_586_] Excel Programming 0 October 6th 04 03:16 PM
Is Workbook read-only because of file permission or because file is already opened? balexis Excel Programming 0 September 29th 04 02:29 PM


All times are GMT +1. The time now is 01:49 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"