473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Excel Sheet Wont Open In 2007.

anoble1
245 128KB
Hopefully I can explain this.
I have a main excel sheet that when it opens it grabs data from 8 other spread sheets and updates numbers on the main one. Well, when it opens in Excel 2007
I get a error message 'C:\/" cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only.

In the code it is saving a copy to the C: so it can be opened multiple times by different users.

Expand|Select|Wrap|Line Numbers
  1. Public Function GetData()
  2. 'Initially, this takes the spreadsheet and copies it to the C: drive
  3. 'This is done, so many people can access it at the same time
  4. 'Note:  I had to create a few functions, so if you see something you don't recognize,
  5. 'Look further downS
  6.  
  7.         'If the spreadsheet is a copy
  8.         If ActiveWorkbook.path <> "C:" Then
  9.             path = pathName
  10.         'If it isn't, then assign the variable path the value of the path on the s drive
  11.         Else
  12.             path = "S:\Workgroups\APC Power Delivery\STORM\Southern Company Shared Data\Contractor Contact Assignments\"
  13.         End If
  14.  
  15.         'This causes Excel to not display the "You are about to delete" message
  16.         Application.DisplayAlerts = False
  17.  
  18.         'Save a copy to the C drive
  19.         ActiveWorkbook.SaveAs "C:/" & getName
  20.  
  21.         'Display the caption
  22.         frmWait.Show
  23.         frmWait.Label1.Caption = "Initializing"
  24.         frmWait.Repaint
  25.  
  26.  
  27.         Dim i As Integer
  28.  
  29.         'initialize the variables
  30.         Dim opCo As Integer
  31.         opCo = 1
  32.  
  33.         Dim linePlaceHolder As Integer
  34.         Dim treePlaceHolder As Integer
  35.         Dim oldLinePlaceHolder As Integer
  36.         Dim oldTreePlaceHolder As Integer
  37.  
  38.  
  39.         Dim destSheet As Worksheet
  40.         Dim destsheet2 As Worksheet
  41.         Dim copysheet As Excel.Worksheet
  42.         Set destSheet = ActiveWorkbook.Worksheets(1)        'This worksheet is the one for the line contractors
  43.         Set destsheet2 = ActiveWorkbook.Worksheets(2)       'This one is the worksheet for the tree contractors
  44.  
  45.         'They are currently protected, this unprotects them
  46.         destSheet.Unprotect "pdcs"
  47.         destsheet2.Unprotect "pdcs"
  48.  
  49.         'Delete all current data, except for the the headers, which start at row 5
  50.         destSheet.Range("A5:AU10000").EntireRow.Delete
  51.         destsheet2.Range("A5:AU10000").EntireRow.Delete
  52.  
  53.         'Initializes for working in Excel, using vba
  54.         Dim appExcel As New Excel.Application
  55.         Dim wkbk As Excel.Workbook
  56.  
  57.         Set appExcel = Excel.Application
  58.  
  59.         'Set place holder to 5, which is the row that the first data line will appear on
  60.         linePlaceHolder = 5
  61.         treePlaceHolder = 5
  62.  
  63.         'Go through list of operating companies (opCo's)
  64.         Do While opCo < 5
  65.             ' Get OpCo's Lines
  66.  
  67.             'Adjust the label caption
  68.             frmWait.Label1.Caption = "Getting " & getOpCos(opCo) & "'s info."
  69.             frmWait.Repaint
  70.  
  71.             'Open the workbook for the appropriate file, which will be the line workbook for the appropriate opco
  72.             Set wkbk = appExcel.Workbooks.Open(path & getFileName(opCo, "Line"), , True)
  73.             'Set variable copysheet, which contains the source data to the first worksheet
  74.             Set copysheet = appExcel.Sheets(1)
  75.  
  76.             'Sets variable, oldLinePlaceHolder to whatever the previous placeholder was, the inital value will be 5
  77.             oldLinePlaceHolder = oldLinePlaceHolder + linePlaceHolder
  78.             'Readjust linePlaceHolder to when "End" appears in the spreadsheet
  79.             linePlaceHolder = getStoppingRow(4, opCo, "Line")
  80.  
  81.             'Copy from what was in the range from "A6"(starting for its data) to whenever "End" was reached,
  82.             'Then place it into the value, starting with whatever the old placeholder was
  83.             copysheet.Range("A6:AW" & linePlaceHolder - 1).Copy destSheet.Cells(oldLinePlaceHolder, 1)
  84.  
  85.             opColors(opCo) = copysheet.Range("A6:A6").Interior.ColorIndex
  86.  
  87.             'Clean blank lines
  88.             CleanLines destSheet, oldLinePlaceHolder
  89.  
  90.             'close the opco line workbook
  91.             wkbk.Close
  92.  
  93. ' Get OpCo's Trees  - now we repeat for the tree contractors
  94.  
  95.             'Open the workbook for the appropriate file, which will be the tree workbook for the appropriate opco
  96.             Set wkbk = appExcel.Workbooks.Open(path & getFileName(opCo, "Tree"), , True)
  97.             'Set variable copysheet, which contains the source data to the first worksheet
  98.             Set copysheet = appExcel.Sheets(1)
  99.  
  100.             'Sets variable, oldTreePlaceHolder to whatever the previous placeholder was, the inital value will be 5
  101.             oldTreePlaceHolder = oldTreePlaceHolder + treePlaceHolder
  102.             'Readjust treePlaceHolder to when "End" appears in the spreadsheet
  103.             treePlaceHolder = getStoppingRow(4, opCo, "Tree")
  104.  
  105.             'Copy from what was in the range from "A6"(starting for its data) to whenever "End" was reached,
  106.             'Then place it into the value, starting with whatever the old placeholder was
  107.             copysheet.Range("A6:AW" & treePlaceHolder - 1).Copy destsheet2.Cells(oldTreePlaceHolder, 1)
  108.  
  109.             'Clean blank lines
  110.             CleanLines destsheet2, oldTreePlaceHolder
  111.  
  112.             opColors(opCo) = copysheet.Range("A6:A6").Interior.ColorIndex
  113.  
  114.             wkbk.Close
  115.  
  116.             'Increment to next opco
  117.             opCo = opCo + 1
  118.         Loop
  119.  
  120.         frmWait.Label1.Caption = "Finishing."
  121.         frmWait.Repaint
  122.  
  123.         'Set appropriate colors for both sheets
  124.         setColors destSheet
  125.         setColors destsheet2
  126.  
  127.         'Clean blank lines
  128.         CleanLines destSheet, oldLinePlaceHolder
  129.         CleanLines destsheet2, oldTreePlaceHolder
  130.  
  131.         'Set lable of when the spreadsheet was last updated
  132.         destSheet.Range("C1") = "Last updated at " & Now
  133.         destsheet2.Range("C1") = "Last updated at " & Now
  134.  
  135.         'Adjust width of all columns for both sheets
  136.         destSheet.Columns.AutoFit
  137.         destsheet2.Columns.AutoFit
  138.  
  139.         'Protect them, and save with previous password
  140.         destSheet.Protect "pdcs", True, True, True
  141.         destsheet2.Protect "pdcs", True, True, True
  142.         ActiveWorkbook.Save
  143.  
  144.         'Hide form, and redisplay alerts again
  145.         frmWait.Hide
  146.         ActiveWorkbook.SaveAs "C:/" & getName
  147.         Application.DisplayAlerts = True
  148.  
  149. End Function
  150.  
Apr 7 '10 #1
3 2016
CyberSoftHari
487 Expert 256MB
Try yourself and post your query or part of code which gives error. Do not expect that anyone here to execute your entire code and solve for you.
Apr 8 '10 #2
Stewart Ross
2,545 Expert Mod 2GB
I echo CyberSoftHari's comment about proper testing and debugging yourself. However, why do you refer to the file on drive C in this way?

Expand|Select|Wrap|Line Numbers
  1. ActiveWorkbook.SaveAs "C:/" & getName
Surely it should be

Expand|Select|Wrap|Line Numbers
  1. ActiveWorkbook.SaveAs "C:\" & getName
You do this more than once, so make sure you change all occurrences in your code.

Debugging should be easier for you than for us - you can surely use the debugger to show you the values of variables when your code fails, and see for yourself that you've used a forward slash instead of a back slash character.

Also, the error message you received really was pointing you in the right direction - so you should have focused on the lines that involved saving the file to drive C!

-Stewart
Apr 8 '10 #3
anoble1
245 128KB
Sorry for all the confusion. I have been using this spread sheet for office 2003 for 5 years now and everything works PERFECT for 2007. I took your advise and changed the C:/ to C:\ and it worked perfectly. I guess I wasn't thinking when I wrote it. I am just wondering how it worked before lol.

Thanks for all the help!
Apr 12 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
5
by: HDI | last post by:
Hi, How can I programmatically open a password protected excel-sheet? Thx
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
1
ammoos
by: ammoos | last post by:
Hi friends Actually my problem is with the excel sheets. I have convert one of my access report to excel sheet that have too many records. After I convert the report to excel successfully, I cant...
12
by: forrestgump | last post by:
I am currently trying to create VBA to send a specified excel sheet to varied email sources. I currently have the code below which sends the attachment in an email to a specified source e.g....
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
1
by: PeacefulSoul | last post by:
Hello, I have a lot of excel sheets which columns are slightly different, i want to import all of these sheets (one at a time) into ONE SQL TABLE. I'll give an example : Say ive written the...
2
by: Sally O Askar | last post by:
Please help me, I am designing a small application that takes an excel sheet , this sheet contains my students marks inside a table named grade1. I want to import this table to my access table I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.