[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

run excel macro in shared workbook

Posted on 2011-09-29
8
Medium Priority
?
507 Views
Last Modified: 2012-05-12
Hi Gents,

I am trying to run a macro in a shared workbook but the macro fails. If the workbook is "un -shared" then there are no issues at all.
The macro fails I think because I used the ActiveSheet. syntax and probably excel cannot determine which one is the active sheet as multiple instances are open at any given time.
I get run time error '1004' saying the" this command is not allowed on a shared workbook" etc.

Any idea how to get around this?

I am just trying to import some data in the workbook sheet with that macro and this operation has to be done while excel is in shared mode.

Any help would be greatly appreciated
Sub AA_Importandupdatedata()
'Sub Import_Data_friday()
'
' Import_Data_friday Macro
' Macro recorded 25/09/2011 by Admin
'
Columns("BK:BM").Select
    Selection.ClearContents
'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Carina_DWOR\ExportData\Friday.txt", Destination:=Range("BK1"))
        .Name = "Monday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = xlWindows
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .Refresh BackgroundQuery:=False
    End With
    
Range("BK1").Select
Dim rng
Dim sCell
Dim Startcell
Do
sCell = ActiveCell.Value
Startcell = ActiveCell.Address

 ActiveCell.Offset(0, 1).Select
 Selection.Copy
 Range(sCell).Select
  
 Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
 False, Transpose:=False
 Range(Startcell).Select
 ActiveCell.Offset(1, 0).Select
 Loop Until IsEmpty(ActiveCell.Offset(0, 1))
 Range("C5").Select
End Sub

Open in new window

0
Comment
Question by:Latzi_Marian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 50
ID: 36818846
Hello,

Shared workbooks should be avoided. They cause all kinds of trouble and will eventually become corrupt. VBA, worksheet protection and shared workbooks don't play well together.

The unanimous advice of advanced Excel users world-wide is not to use shared workbooks. Excel was not designed for simultaneous multi-user access. If you need such functionality, you should migrate to a database like Access or SQL.

Sorry, that's probably not what you want to hear, but shared workbooks are impossible to troubleshoot, since they can become corrupt at any time and will not necessarily show consistent behaviour.

cheers, teylyn
0
 

Author Comment

by:Latzi_Marian
ID: 36818897
You are right .This is not what I wanted to hear at all. I know that excel hasn't been designed for a multiuser environment and it's very limited if used in such way. Unfortunately I will have to put up with it as the customer is simply not prepared to upgrade to a web based environment.

I actually process all the information which I want to display on that excel sheet in a SQL database using SP's and DTS's and output a flat file which should be "grabbed" by the excel macro and displayed.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36890159
In addition to what teylyn said, your specific issue here is trying to add a querytable. You cannot do that (in code or manually) in a shared workbook.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Latzi_Marian
ID: 36890514
Well you can but it's a very long way around . I did actually told the people involved in this that doing it in Excel is just looking for trouble and wasting time. I will try to do it in Access. That should be ok I think. What's your thoughts?

Obviously doing it in a web based environment would be the best but I have to do it in such a way that users can interact with the code behind easily,modify code,add pages ,etc . Access is what they are prepared to upgrade to.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36890518
Access should be fine, assuming you don't have hundreds of users accessing the data simultaneously.
0
 

Author Comment

by:Latzi_Marian
ID: 36890597
No no. The maximum number of users at any given time would not exceed 8. I think it's going to be ok.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 1500 total points
ID: 36890601
OK, Access should cope with that no problem.
0
 

Author Closing Comment

by:Latzi_Marian
ID: 37693897
decided to go with access
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question